{"id":797,"date":"2018-12-03T12:03:37","date_gmt":"2018-12-03T12:03:37","guid":{"rendered":"http:\/\/blog.softreeconsulting.com\/?p=797"},"modified":"2018-12-03T12:03:37","modified_gmt":"2018-12-03T12:03:37","slug":"add-remove-site-columns-site-content-type","status":"publish","type":"post","link":"https:\/\/softreetechnology.com\/blog\/all\/add-remove-site-columns-site-content-type\/","title":{"rendered":"Add and Remove Site Columns from Site Content Type"},"content":{"rendered":"<p>In this blog post, I am going to add and remove site columns in existing site content type.<\/p>\n<p>Content types empower you to arrange, oversee, and handle content reliably across your sites. To view all content types used in the site collection.<br \/>\nOpen SharePoint site<br \/>\nNavigate to site settings -&gt;Under Web designer galleries -&gt; Click Site content type or navigate to this url &#8220;&lt;Site Url&gt;+ \/_layouts\/15\/mngctype.aspx&#8221;<\/p>\n<p>We can view all site contents type. To view details of the content type just click on the content type.<\/p>\n<p>In this example, I am going to add and remove site columns used in Custom Content Types.<br \/>\nHere in this content type, there are two site columns Title, Contact is present. Through our code, we will remove the Contact site column and add a new site column to this content type.<\/p>\n<p><a href=\"http:\/\/blog.softreeconsulting.com\/wp-content\/uploads\/2018\/12\/Img2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-798\" src=\"https:\/\/blog.softreeconsulting.com\/wp-content\/uploads\/2018\/12\/Img2.png\" alt=\"img2\" width=\"1346\" height=\"638\" \/><\/a><\/p>\n<p>The script as follows:-<\/p>\n<p>[code lang=&#8221;c&#8221;]<\/p>\n<p>using System;<br \/>\nusing System.Collections.Generic;<br \/>\nusing System.Linq;<br \/>\nusing System.Text;<br \/>\nusing System.Threading.Tasks;<br \/>\nusing Microsoft.SharePoint.Client;<br \/>\nusing System.Security;<br \/>\nusing System.IO;<\/p>\n<p>namespace AddandRemoveFieldsFromCtype<br \/>\n{<br \/>\nclass Program<br \/>\n{<br \/>\nstatic void Main(string[] args)<br \/>\n{<br \/>\nClientContext ctx = new ClientContext(&#8220;http:\/\/portal\/sites\/site1&#8221;);<br \/>\nWeb web = ctx.Web;<br \/>\nvar password = &#8220;Password&#8221;;<br \/>\nSecureString secureString = new SecureString();<br \/>\nforeach (char c in password.ToCharArray()) secureString.AppendChar(c);<\/p>\n<p>ctx.Credentials = new SharePointOnlineCredentials(&#8220;user@domain.com&#8221;, secureString);<br \/>\nContentTypeCollection ctypecoll = web.ContentTypes;<br \/>\nctx.Load(ctypecoll);<br \/>\nctx.ExecuteQuery();<br \/>\nField fieldToAdd = web.Fields.GetByTitle(&#8220;City&#8221;);<\/p>\n<p>foreach (ContentType ctype in ctypecoll)<br \/>\n{<br \/>\nif (ctype.Name == &#8220;docCtype&#8221;)<br \/>\n{<br \/>\nFieldLinkCreationInformation fieldLinksCreation = new FieldLinkCreationInformation();<br \/>\nfieldLinksCreation.Field = fieldToAdd;<br \/>\nctype.FieldLinks.Add(fieldLinksCreation);<br \/>\nctype.Update(true); \/\/ adding site columns to content type<br \/>\nweb.Update();<\/p>\n<p>Field fieldToRemove = ctype.Fields.GetByTitle(&#8220;Contact&#8221;);<br \/>\nctx.Load(fieldToRemove);<br \/>\nctx.ExecuteQuery();<br \/>\nvar fieldToRemoveId = fieldToRemove.Id;<br \/>\nFieldLinkCollection fieldLinkCollection = ctype.FieldLinks;<br \/>\nctx.Load(fieldLinkCollection);<br \/>\nctx.ExecuteQuery();<br \/>\nforeach (FieldLink fieldLink in fieldLinkCollection)<br \/>\n{<br \/>\nvar fieldLinkId = fieldLink.Id;<br \/>\nif (fieldToRemoveId == fieldLinkId)<br \/>\n{<br \/>\nfieldLink.DeleteObject();<br \/>\nctype.Update(false); \/\/ removing site columns from content type<br \/>\nweb.Update();<br \/>\n}<\/p>\n<p>}<\/p>\n<p>ctx.ExecuteQuery();<\/p>\n<p>}<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n<p>[\/code]<\/p>\n<p>After code executed successfully you can manually navigate to that custom content type, you can find the existing site column is removed and new site columns is added to the content type.<\/p>\n<p><a href=\"http:\/\/blog.softreeconsulting.com\/wp-content\/uploads\/2018\/12\/Img3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-799\" src=\"https:\/\/blog.softreeconsulting.com\/wp-content\/uploads\/2018\/12\/Img3.png\" alt=\"img3\" width=\"1300\" height=\"652\" \/><\/a><\/p>\n<p><strong>This solution is brought to you by our SharePoint professionals.<\/strong><\/p>\n<p><a href=\"http:\/\/www.softreeconsulting.com\/\"><strong>Softree Consulting<\/strong><\/a>\u00a0employs SharePoint consultants; we are a technology services provider with the aim to help companies achieve exceptional performance through SharePoint. Our dedicated team of SharePoint consultants has the right bent of mind to understand and execute customer requirements.<\/p>\n<p>Be it SPFx or SharePoint add-in developments,\u00a0<a href=\"http:\/\/www.softreeconsulting.com\/sharepoint-2019\/\"><strong>SharePoint 2019 developments<\/strong><\/a>, web part developments, migrating from SharePoint 2010\/2013 to SharePoint 2013\/2016\/Office 365, Office 365,\u00a0SharePoint hosted apps development\u00a0or something else in SharePoint, we strive to deliver the best<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog post, I am going to add and remove site columns in existing site content type. Content types empower you to arrange, oversee, and handle content reliably across your sites. To view all content types used in the site collection. Open SharePoint site Navigate to site settings -&gt;Under Web designer galleries -&gt; Click Site content type or navigate [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[129],"tags":[189,190,191,192],"class_list":["post-797","post","type-post","status-publish","format-standard","hentry","category-all","tag-add-remove-fields-from-site-content-type","tag-how-to-add-existing-site-columns-to-a-content-type-in-sharepoint-2019","tag-how-to-added-a-column-to-a-content-type","tag-how-to-remove-site-columns-from-a-content-type"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Add and Remove Site Columns from Site Content Type - Softree Technology<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/softreetechnology.com\/blog\/all\/add-remove-site-columns-site-content-type\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Add and Remove Site Columns from Site Content Type - Softree Technology\" \/>\n<meta property=\"og:description\" content=\"In this blog post, I am going to add and remove site columns in existing site content type. Content types empower you to arrange, oversee, and handle content reliably across your sites. To view all content types used in the site collection. Open SharePoint site Navigate to site settings -&gt;Under Web designer galleries -&gt; Click Site content type or navigate [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/softreetechnology.com\/blog\/all\/add-remove-site-columns-site-content-type\/\" \/>\n<meta property=\"og:site_name\" content=\"Softree Technology\" \/>\n<meta property=\"article:published_time\" content=\"2018-12-03T12:03:37+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Add and Remove Site Columns from Site Content Type - Softree Technology","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/softreetechnology.com\/blog\/all\/add-remove-site-columns-site-content-type\/","og_locale":"en_US","og_type":"article","og_title":"Add and Remove Site Columns from Site Content Type - Softree Technology","og_description":"In this blog post, I am going to add and remove site columns in existing site content type. Content types empower you to arrange, oversee, and handle content reliably across your sites. To view all content types used in the site collection. Open SharePoint site Navigate to site settings -&gt;Under Web designer galleries -&gt; Click Site content type or navigate [&hellip;]","og_url":"https:\/\/softreetechnology.com\/blog\/all\/add-remove-site-columns-site-content-type\/","og_site_name":"Softree Technology","article_published_time":"2018-12-03T12:03:37+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/softreetechnology.com\/blog\/all\/add-remove-site-columns-site-content-type\/#article","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/all\/add-remove-site-columns-site-content-type\/"},"author":{"name":"admin","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/98740297642f06debccdcee2de84086b"},"headline":"Add and Remove Site Columns from Site Content Type","datePublished":"2018-12-03T12:03:37+00:00","mainEntityOfPage":{"@id":"https:\/\/softreetechnology.com\/blog\/all\/add-remove-site-columns-site-content-type\/"},"wordCount":446,"commentCount":0,"publisher":{"@id":"https:\/\/softreetechnology.com\/blog\/#organization"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/all\/add-remove-site-columns-site-content-type\/#primaryimage"},"thumbnailUrl":"https:\/\/blog.softreeconsulting.com\/wp-content\/uploads\/2018\/12\/Img2.png","keywords":["add\/ remove fields from site content type","how to add existing site columns to a content type in sharepoint 2019","how to added a column to a content type","how to remove site columns from a content type"],"articleSection":["All"],"inLanguage":"en","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/softreetechnology.com\/blog\/all\/add-remove-site-columns-site-content-type\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/softreetechnology.com\/blog\/all\/add-remove-site-columns-site-content-type\/","url":"https:\/\/softreetechnology.com\/blog\/all\/add-remove-site-columns-site-content-type\/","name":"Add and Remove Site Columns from Site Content Type - Softree Technology","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/softreetechnology.com\/blog\/all\/add-remove-site-columns-site-content-type\/#primaryimage"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/all\/add-remove-site-columns-site-content-type\/#primaryimage"},"thumbnailUrl":"https:\/\/blog.softreeconsulting.com\/wp-content\/uploads\/2018\/12\/Img2.png","datePublished":"2018-12-03T12:03:37+00:00","breadcrumb":{"@id":"https:\/\/softreetechnology.com\/blog\/all\/add-remove-site-columns-site-content-type\/#breadcrumb"},"inLanguage":"en","potentialAction":[{"@type":"ReadAction","target":["https:\/\/softreetechnology.com\/blog\/all\/add-remove-site-columns-site-content-type\/"]}]},{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/all\/add-remove-site-columns-site-content-type\/#primaryimage","url":"https:\/\/blog.softreeconsulting.com\/wp-content\/uploads\/2018\/12\/Img2.png","contentUrl":"https:\/\/blog.softreeconsulting.com\/wp-content\/uploads\/2018\/12\/Img2.png"},{"@type":"BreadcrumbList","@id":"https:\/\/softreetechnology.com\/blog\/all\/add-remove-site-columns-site-content-type\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/softreetechnology.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Add and Remove Site Columns from Site Content Type"}]},{"@type":"WebSite","@id":"https:\/\/softreetechnology.com\/blog\/#website","url":"https:\/\/softreetechnology.com\/blog\/","name":"Softree Technology","description":"Celebrating 10+ Years in SharePoint Consulting !","publisher":{"@id":"https:\/\/softreetechnology.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/softreetechnology.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en"},{"@type":"Organization","@id":"https:\/\/softreetechnology.com\/blog\/#organization","name":"Softree Technology","url":"https:\/\/softreetechnology.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/softreetechnology.com\/blog\/wp-content\/uploads\/2023\/03\/cropped-white-logo-soft.png","contentUrl":"https:\/\/softreetechnology.com\/blog\/wp-content\/uploads\/2023\/03\/cropped-white-logo-soft.png","width":844,"height":230,"caption":"Softree Technology"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/98740297642f06debccdcee2de84086b","name":"admin","image":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6fc78c8a7aa3fb0bf43c3b9a2e3962d7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6fc78c8a7aa3fb0bf43c3b9a2e3962d7?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/softreeconsulting.com"],"url":"https:\/\/softreetechnology.com\/blog\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/797","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/comments?post=797"}],"version-history":[{"count":0,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/797\/revisions"}],"wp:attachment":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/media?parent=797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/categories?post=797"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/tags?post=797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}