{"id":208,"date":"2015-12-29T07:34:32","date_gmt":"2015-12-29T07:34:32","guid":{"rendered":"http:\/\/www.softreeconsulting.com\/?p=208"},"modified":"2015-12-29T07:34:32","modified_gmt":"2015-12-29T07:34:32","slug":"retain-internal-name-of-list-columns-while-copying-list-from-one-site-to-another-site-using-client-object-model","status":"publish","type":"post","link":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retain-internal-name-of-list-columns-while-copying-list-from-one-site-to-another-site-using-client-object-model\/","title":{"rendered":"Retain internal name of list columns while copying list from One site to another site using client object model"},"content":{"rendered":"<p>Internal name is a property of list fields which is read only and cannot be edited.<\/p>\n<p>Internal name is created according to field title while creating field. If we rename field title internal name will not be changed.<\/p>\n<p>If one user has created a custom column and give title=\u201dColumn\u201d then internal name will be \u201cColumn\u201d<\/p>\n<p>After renaming field title &#8216;Internal name&#8217; will be same as previous.<br \/>Below Code describes how to retain field internal name while copying or migrating.If field will migrate or Copy from source list to destination list after rename then field in destination list will be created a new Title.<\/p>\n\n\n<pre class=\"wp-block-code\"><code>using\u00a0Microsoft.SharePoint.Client;\u00a0namespace\u00a0ConsoleApplication10 {\n\n\/\/this class is used to store data from schema xml\n\npublic\u00a0class\u00a0FieldInfoInternalName\n\n{\n\npublic\u00a0string\u00a0InternalName {\u00a0get;\u00a0set; }\n\npublic\u00a0string\u00a0DisplayName {\u00a0get;\u00a0set; }\n\n}\n\nclass\u00a0Program\n\n{\n\nstatic\u00a0void\u00a0Main(string[] args)\n\n{\n\nstring\u00a0sourceSiteUrl =\u00a0\"Enter Source Url\u201d;\n\nstring\u00a0destinationSiteUrl = \"Enter Destination url\";\n\nstring\u00a0sourceListName =\u00a0\"Custom List\";\n\nstring\u00a0destinationListName =\u00a0\"New List\";\n\nFieldCollection\u00a0srcFieldColl =\u00a0null;\n\nusing\u00a0(ClientContext\u00a0ctx =\u00a0new\u00a0ClientContext(sourceSiteUrl))\n\n{\n\nctx.Credentials =\u00a0new\u00a0System.Net.NetworkCredential(\"UserName\",\u00a0\"Password\");\n\nWeb\u00a0web = ctx.Web;\n\nctx.Load(web, w => w.Lists);\n\nList\u00a0list = web.Lists.GetByTitle(sourceListName);\n\nctx.Load(list, l => l.Fields.Include(\n\nfld => fld.SchemaXml,\n\nfld => fld.Id,\n\nfld => fld.Title,\n\nfld => fld.Hidden,\n\nfld => fld.ReadOnlyField));\n\nctx.ExecuteQuery();\n\n\/\/Store all fields from source list in a field collection\n\nsrcFieldColl = list.Fields;\n\n}\n\nusing\u00a0(ClientContext\u00a0destContext =\u00a0new\u00a0ClientContext(destinationSiteUrl))\n\n{\n\ndestContext.Credentials =\u00a0new\u00a0System.Net.NetworkCredential(\"UserName\",\u00a0\"Password\");\n\nWeb\u00a0web = destContext.Web;\n\ndestContext.Load(web, w => w.Lists);\n\nList\u00a0list = web.Lists.GetByTitle(destinationListName);\n\ndestContext.Load(list, l => l.Fields);\n\ndestContext.ExecuteQuery();\n\nfor\u00a0(int\u00a0iFieldCount = 0; iFieldCount &lt; srcFieldColl.Count; iFieldCount++)\n\n{\n\nField\u00a0srcField = srcFieldColl[iFieldCount];\n\nif (!srcField.ReadOnlyField &amp;&amp; !srcField.Hidden)\n\n{\n\nstring\u00a0fieldSchemaXml = srcField.SchemaXml;\n\nCreateFieldAsInternalName(ref\u00a0fieldSchemaXml);\n\nField\u00a0field = list.Fields.AddFieldAsXml(fieldSchemaXml,\u00a0false,\u00a0AddFieldOptions.DefaultValue);\n\nfield.Title = srcField.Title;\/\/Update title\n\nfield.Update();\n\n}\n\n}\n\n}\n\n}\n\nprivate\u00a0static\u00a0void\u00a0CreateFieldAsInternalName(ref\u00a0string schemaXml)\n\n{\n\nSystem.Xml.Linq.XDocument\u00a0xDocument;\n\nstring\u00a0internalName =\u00a0string.Empty;\n\nstring\u00a0displayName =\u00a0string.Empty;\n\ntry\n\n{\n\n\/\/ retrieve internal name and display name from schemaxml\n\nusing\u00a0(System.IO.StringReader\u00a0reader =\u00a0new\u00a0System.IO.StringReader(schemaXml))\n\n{\n\nxDocument = System.Xml.Linq.XDocument.Load(reader);\n\nList&lt;FieldInfoInternalName> FieldMetaInfoSchemaXml =\n\n(\n\nfrom\u00a0l in xDocument.Descendants(\"Field\")\n\nselect\u00a0new\u00a0FieldInfoInternalName\n\n{\n\nInternalName = l.Attribute(\"StaticName\").Value,\n\nDisplayName = l.Attribute(\"DisplayName\").Value\n\n}\n\n).ToList();\n\nforeach\u00a0(var\u00a0item\u00a0in\u00a0FieldMetaInfoSchemaXml)\n\n{\n\ninternalName = item.InternalName;\n\ndisplayName = item.DisplayName;\n\n}\n\n}\n\nif\u00a0(displayName.Contains(\"&amp;\"))\n\ndisplayName = displayName.Replace(\"&amp;\",\u00a0\"&amp;\");\n\nif\u00a0(displayName.Contains(\"&lt;\"))\n\ndisplayName = displayName.Replace(\"&lt;\",\u00a0\"&lt;\");\n\nif\u00a0(displayName.Contains(\">\"))\n\ndisplayName = displayName.Replace(\">\",\u00a0\">\");\n\nif\u00a0(displayName.Contains(\"\"\"))\n\ndisplayName = displayName.Replace(\"\"\",\u00a0\"\"\");\n\n\/\/Replace display name with internal name\n\nif\u00a0(schemaXml.Contains(displayName) &amp;&amp; displayName != internalName)\n\nschemaXml = schemaXml.Replace(displayName, internalName);\n\n}\n\ncatch\u00a0{ }\n\n}\n\n}\n\n}<\/code><\/pre>\n\n\n\n<p><strong>This solution is brought to you by our SharePoint professionals.<\/strong><\/p>\n\n\n\n<p><strong><a rel=\"noreferrer noopener\" aria-label=\"Softree Consulting (opens in a new tab)\" href=\"http:\/\/www.softreeconsulting.com\/\" target=\"_blank\">Softree Technology<\/a><\/strong>\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\n\n\n<p>e it SPFx or SharePoint add-in developments,\u00a0<strong>SharePoint 2019 developments<\/strong>, web part developments, migrating from SharePoint 2010\/2013 to SharePoint 2013\/2016\/Office 365, Office 365,\u00a0SharePoint hosted apps development<a rel=\"noreferrer noopener\" aria-label=\"SharePoint hosted apps development\u00a0 (opens in a new tab)\" href=\"http:\/\/www.softreeconsulting.com\/sharepoint-azure-ad\/\" target=\"_blank\">\u00a0<\/a>or something else in SharePoint, we strive to deliver the best<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Internal name is a property of list fields which is read only and cannot be edited. Internal name is created according to field title while creating field. If we rename field title internal name will not be changed. If one user has created a custom column and give title=\u201dColumn\u201d then internal name will be \u201cColumn\u201d After renaming field title &#8216;Internal [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":392,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[50,70,71,72,73,74],"class_list":["post-208","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sharepoint","tag-client-object-model","tag-retain-internal-name","tag-retain-internal-name-of-column","tag-retain-internal-name-of-field","tag-retain-internal-name-of-list-column","tag-retain-internal-name-of-list-field"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Retain internal name of list columns while copying list from One site to another site using client object model - 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\/sharepoint\/retain-internal-name-of-list-columns-while-copying-list-from-one-site-to-another-site-using-client-object-model\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Retain internal name of list columns while copying list from One site to another site using client object model - Softree Technology\" \/>\n<meta property=\"og:description\" content=\"Internal name is a property of list fields which is read only and cannot be edited. Internal name is created according to field title while creating field. If we rename field title internal name will not be changed. If one user has created a custom column and give title=\u201dColumn\u201d then internal name will be \u201cColumn\u201d After renaming field title &#8216;Internal [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/softreetechnology.com\/blog\/sharepoint\/retain-internal-name-of-list-columns-while-copying-list-from-one-site-to-another-site-using-client-object-model\/\" \/>\n<meta property=\"og:site_name\" content=\"Softree Technology\" \/>\n<meta property=\"article:published_time\" content=\"2015-12-29T07:34:32+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=\"3 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Retain internal name of list columns while copying list from One site to another site using client object model - 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\/sharepoint\/retain-internal-name-of-list-columns-while-copying-list-from-one-site-to-another-site-using-client-object-model\/","og_locale":"en_US","og_type":"article","og_title":"Retain internal name of list columns while copying list from One site to another site using client object model - Softree Technology","og_description":"Internal name is a property of list fields which is read only and cannot be edited. Internal name is created according to field title while creating field. If we rename field title internal name will not be changed. If one user has created a custom column and give title=\u201dColumn\u201d then internal name will be \u201cColumn\u201d After renaming field title &#8216;Internal [&hellip;]","og_url":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retain-internal-name-of-list-columns-while-copying-list-from-one-site-to-another-site-using-client-object-model\/","og_site_name":"Softree Technology","article_published_time":"2015-12-29T07:34:32+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retain-internal-name-of-list-columns-while-copying-list-from-one-site-to-another-site-using-client-object-model\/#article","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retain-internal-name-of-list-columns-while-copying-list-from-one-site-to-another-site-using-client-object-model\/"},"author":{"name":"admin","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/98740297642f06debccdcee2de84086b"},"headline":"Retain internal name of list columns while copying list from One site to another site using client object model","datePublished":"2015-12-29T07:34:32+00:00","mainEntityOfPage":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retain-internal-name-of-list-columns-while-copying-list-from-one-site-to-another-site-using-client-object-model\/"},"wordCount":208,"commentCount":18,"publisher":{"@id":"https:\/\/softreetechnology.com\/blog\/#organization"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retain-internal-name-of-list-columns-while-copying-list-from-one-site-to-another-site-using-client-object-model\/#primaryimage"},"thumbnailUrl":"","keywords":["Client Object Model","Retain internal name","Retain internal name of column","Retain internal name of field","Retain internal name of list column","Retain internal name of list field"],"articleSection":["SharePoint"],"inLanguage":"en","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/softreetechnology.com\/blog\/sharepoint\/retain-internal-name-of-list-columns-while-copying-list-from-one-site-to-another-site-using-client-object-model\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retain-internal-name-of-list-columns-while-copying-list-from-one-site-to-another-site-using-client-object-model\/","url":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retain-internal-name-of-list-columns-while-copying-list-from-one-site-to-another-site-using-client-object-model\/","name":"Retain internal name of list columns while copying list from One site to another site using client object model - Softree Technology","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retain-internal-name-of-list-columns-while-copying-list-from-one-site-to-another-site-using-client-object-model\/#primaryimage"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retain-internal-name-of-list-columns-while-copying-list-from-one-site-to-another-site-using-client-object-model\/#primaryimage"},"thumbnailUrl":"","datePublished":"2015-12-29T07:34:32+00:00","breadcrumb":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retain-internal-name-of-list-columns-while-copying-list-from-one-site-to-another-site-using-client-object-model\/#breadcrumb"},"inLanguage":"en","potentialAction":[{"@type":"ReadAction","target":["https:\/\/softreetechnology.com\/blog\/sharepoint\/retain-internal-name-of-list-columns-while-copying-list-from-one-site-to-another-site-using-client-object-model\/"]}]},{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retain-internal-name-of-list-columns-while-copying-list-from-one-site-to-another-site-using-client-object-model\/#primaryimage","url":"","contentUrl":""},{"@type":"BreadcrumbList","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retain-internal-name-of-list-columns-while-copying-list-from-one-site-to-another-site-using-client-object-model\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/softreetechnology.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Retain internal name of list columns while copying list from One site to another site using client object model"}]},{"@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\/208","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=208"}],"version-history":[{"count":0,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/208\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/media?parent=208"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/categories?post=208"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/tags?post=208"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}