{"id":1724,"date":"2014-09-30T17:18:17","date_gmt":"2014-09-30T16:18:17","guid":{"rendered":"http:\/\/www.stuartroberts.net\/?p=1724"},"modified":"2026-10-16T16:54:23","modified_gmt":"2026-10-16T15:54:23","slug":"quick-tip-21","status":"publish","type":"post","link":"http:\/\/www.stuartroberts.net\/index.php\/2014\/09\/30\/quick-tip-21\/","title":{"rendered":"Add Field with XML"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>SharePoint Short #21<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A quick short today \ud83d\ude42<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Instead of adding new fields to a content type or list creating the object (SPFieldText, etc.) and adding it, simply pass the XML definition for whatever field you are looking to create into the AddFieldAsXml method of the Fields collection.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\npublic void AddFieldToList(SPList list, string xmlDefinition)\n{\n    string fieldName = list.Fields.AddFieldAsXml(xmlDefinition);\n    SPField newField = list.Fields.GetField(fieldName);\n    \/\/ Do whatever you need to with the new field\n    \/\/\n    \/\/ and then update it.\n    newField.Update();\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">The xmlDefinition is simply a copy of the Field tag, for example from a content type definition.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SharePoint Short #21 A quick short today \ud83d\ude42 Instead of adding new fields to a content type or list creating the object (SPFieldText, etc.) and adding it, simply pass the XML definition for whatever field you are looking to create &hellip; <a href=\"http:\/\/www.stuartroberts.net\/index.php\/2014\/09\/30\/quick-tip-21\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[3,44],"tags":[45],"class_list":["post-1724","post","type-post","status-publish","format-standard","hentry","category-sharepoint","category-shorts","tag-sharepoint-short"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.3 - aioseo.com -->\n\t<meta name=\"description\" content=\"How to programmatically add a SharePoint field to a list using XML.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Stu\"\/>\n\t<meta name=\"keywords\" content=\"sharepoint,sps,sp,addfieldasxml,shorts\" \/>\n\t<link rel=\"canonical\" href=\"http:\/\/www.stuartroberts.net\/index.php\/2014\/09\/30\/quick-tip-21\/\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.3\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_GB\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Stuart Roberts on all things SharePoint |\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Quick Tip #21 - Add Field with XML | Stuart Roberts on all things SharePoint\" \/>\n\t\t<meta property=\"og:description\" content=\"How to programmatically add a SharePoint field to a list using XML.\" \/>\n\t\t<meta property=\"og:url\" content=\"http:\/\/www.stuartroberts.net\/index.php\/2014\/09\/30\/quick-tip-21\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2014-09-30T16:18:17+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-10-16T15:54:23+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@SharePointStu\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Quick Tip #21 - Add Field with XML | Stuart Roberts on all things SharePoint\" \/>\n\t\t<meta name=\"twitter:description\" content=\"How to programmatically add a SharePoint field to a list using XML.\" \/>\n\t\t<meta name=\"twitter:creator\" content=\"@SharePointStu\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\\\/\\\/www.stuartroberts.net\\\/index.php\\\/2014\\\/09\\\/30\\\/quick-tip-21\\\/#article\",\"name\":\"Quick Tip #21 - Add Field with XML | Stuart Roberts on all things SharePoint\",\"headline\":\"Add Field with XML\",\"author\":{\"@id\":\"http:\\\/\\\/www.stuartroberts.net\\\/index.php\\\/author\\\/admin\\\/#author\"},\"publisher\":{\"@id\":\"http:\\\/\\\/www.stuartroberts.net\\\/#person\"},\"image\":{\"@type\":\"ImageObject\",\"@id\":\"http:\\\/\\\/www.stuartroberts.net\\\/index.php\\\/2014\\\/09\\\/30\\\/quick-tip-21\\\/#articleImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/503cb376bab10c66a6bde71d1514dcab2eab4ec44a2f82ef597ca87af61bf1cd?s=96&d=retro&r=g\",\"width\":96,\"height\":96,\"caption\":\"Stu\"},\"datePublished\":\"2014-09-30T17:18:17+01:00\",\"dateModified\":\"2026-10-16T16:54:23+01:00\",\"inLanguage\":\"en-GB\",\"mainEntityOfPage\":{\"@id\":\"http:\\\/\\\/www.stuartroberts.net\\\/index.php\\\/2014\\\/09\\\/30\\\/quick-tip-21\\\/#webpage\"},\"isPartOf\":{\"@id\":\"http:\\\/\\\/www.stuartroberts.net\\\/index.php\\\/2014\\\/09\\\/30\\\/quick-tip-21\\\/#webpage\"},\"articleSection\":\"SharePoint, Shorts, SharePoint Short\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\\\/\\\/www.stuartroberts.net\\\/index.php\\\/2014\\\/09\\\/30\\\/quick-tip-21\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"http:\\\/\\\/www.stuartroberts.net\\\/#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\\\/\\\/www.stuartroberts.net\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"http:\\\/\\\/www.stuartroberts.net\\\/index.php\\\/category\\\/sharepoint\\\/#listItem\",\"name\":\"SharePoint\"}},{\"@type\":\"ListItem\",\"@id\":\"http:\\\/\\\/www.stuartroberts.net\\\/index.php\\\/category\\\/sharepoint\\\/#listItem\",\"position\":2,\"name\":\"SharePoint\",\"item\":\"http:\\\/\\\/www.stuartroberts.net\\\/index.php\\\/category\\\/sharepoint\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"http:\\\/\\\/www.stuartroberts.net\\\/index.php\\\/2014\\\/09\\\/30\\\/quick-tip-21\\\/#listItem\",\"name\":\"Add Field with XML\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"http:\\\/\\\/www.stuartroberts.net\\\/#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"http:\\\/\\\/www.stuartroberts.net\\\/index.php\\\/2014\\\/09\\\/30\\\/quick-tip-21\\\/#listItem\",\"position\":3,\"name\":\"Add Field with XML\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"http:\\\/\\\/www.stuartroberts.net\\\/index.php\\\/category\\\/sharepoint\\\/#listItem\",\"name\":\"SharePoint\"}}]},{\"@type\":\"Person\",\"@id\":\"http:\\\/\\\/www.stuartroberts.net\\\/#person\",\"name\":\"Stu\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"http:\\\/\\\/www.stuartroberts.net\\\/index.php\\\/2014\\\/09\\\/30\\\/quick-tip-21\\\/#personImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/503cb376bab10c66a6bde71d1514dcab2eab4ec44a2f82ef597ca87af61bf1cd?s=96&d=retro&r=g\",\"width\":96,\"height\":96,\"caption\":\"Stu\"}},{\"@type\":\"Person\",\"@id\":\"http:\\\/\\\/www.stuartroberts.net\\\/index.php\\\/author\\\/admin\\\/#author\",\"url\":\"http:\\\/\\\/www.stuartroberts.net\\\/index.php\\\/author\\\/admin\\\/\",\"name\":\"Stu\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"http:\\\/\\\/www.stuartroberts.net\\\/index.php\\\/2014\\\/09\\\/30\\\/quick-tip-21\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/503cb376bab10c66a6bde71d1514dcab2eab4ec44a2f82ef597ca87af61bf1cd?s=96&d=retro&r=g\",\"width\":96,\"height\":96,\"caption\":\"Stu\"}},{\"@type\":\"WebPage\",\"@id\":\"http:\\\/\\\/www.stuartroberts.net\\\/index.php\\\/2014\\\/09\\\/30\\\/quick-tip-21\\\/#webpage\",\"url\":\"http:\\\/\\\/www.stuartroberts.net\\\/index.php\\\/2014\\\/09\\\/30\\\/quick-tip-21\\\/\",\"name\":\"Quick Tip #21 - Add Field with XML | Stuart Roberts on all things SharePoint\",\"description\":\"How to programmatically add a SharePoint field to a list using XML.\",\"inLanguage\":\"en-GB\",\"isPartOf\":{\"@id\":\"http:\\\/\\\/www.stuartroberts.net\\\/#website\"},\"breadcrumb\":{\"@id\":\"http:\\\/\\\/www.stuartroberts.net\\\/index.php\\\/2014\\\/09\\\/30\\\/quick-tip-21\\\/#breadcrumblist\"},\"author\":{\"@id\":\"http:\\\/\\\/www.stuartroberts.net\\\/index.php\\\/author\\\/admin\\\/#author\"},\"creator\":{\"@id\":\"http:\\\/\\\/www.stuartroberts.net\\\/index.php\\\/author\\\/admin\\\/#author\"},\"datePublished\":\"2014-09-30T17:18:17+01:00\",\"dateModified\":\"2026-10-16T16:54:23+01:00\"},{\"@type\":\"WebSite\",\"@id\":\"http:\\\/\\\/www.stuartroberts.net\\\/#website\",\"url\":\"http:\\\/\\\/www.stuartroberts.net\\\/\",\"name\":\"Stuart Roberts on all things SharePoint\",\"inLanguage\":\"en-GB\",\"publisher\":{\"@id\":\"http:\\\/\\\/www.stuartroberts.net\\\/#person\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Quick Tip #21 - Add Field with XML | Stuart Roberts on all things SharePoint","description":"How to programmatically add a SharePoint field to a list using XML.","canonical_url":"http:\/\/www.stuartroberts.net\/index.php\/2014\/09\/30\/quick-tip-21\/","robots":"max-image-preview:large","keywords":"sharepoint,sps,sp,addfieldasxml,shorts","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/www.stuartroberts.net\/index.php\/2014\/09\/30\/quick-tip-21\/#article","name":"Quick Tip #21 - Add Field with XML | Stuart Roberts on all things SharePoint","headline":"Add Field with XML","author":{"@id":"http:\/\/www.stuartroberts.net\/index.php\/author\/admin\/#author"},"publisher":{"@id":"http:\/\/www.stuartroberts.net\/#person"},"image":{"@type":"ImageObject","@id":"http:\/\/www.stuartroberts.net\/index.php\/2014\/09\/30\/quick-tip-21\/#articleImage","url":"https:\/\/secure.gravatar.com\/avatar\/503cb376bab10c66a6bde71d1514dcab2eab4ec44a2f82ef597ca87af61bf1cd?s=96&d=retro&r=g","width":96,"height":96,"caption":"Stu"},"datePublished":"2014-09-30T17:18:17+01:00","dateModified":"2026-10-16T16:54:23+01:00","inLanguage":"en-GB","mainEntityOfPage":{"@id":"http:\/\/www.stuartroberts.net\/index.php\/2014\/09\/30\/quick-tip-21\/#webpage"},"isPartOf":{"@id":"http:\/\/www.stuartroberts.net\/index.php\/2014\/09\/30\/quick-tip-21\/#webpage"},"articleSection":"SharePoint, Shorts, SharePoint Short"},{"@type":"BreadcrumbList","@id":"http:\/\/www.stuartroberts.net\/index.php\/2014\/09\/30\/quick-tip-21\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"http:\/\/www.stuartroberts.net\/#listItem","position":1,"name":"Home","item":"http:\/\/www.stuartroberts.net\/","nextItem":{"@type":"ListItem","@id":"http:\/\/www.stuartroberts.net\/index.php\/category\/sharepoint\/#listItem","name":"SharePoint"}},{"@type":"ListItem","@id":"http:\/\/www.stuartroberts.net\/index.php\/category\/sharepoint\/#listItem","position":2,"name":"SharePoint","item":"http:\/\/www.stuartroberts.net\/index.php\/category\/sharepoint\/","nextItem":{"@type":"ListItem","@id":"http:\/\/www.stuartroberts.net\/index.php\/2014\/09\/30\/quick-tip-21\/#listItem","name":"Add Field with XML"},"previousItem":{"@type":"ListItem","@id":"http:\/\/www.stuartroberts.net\/#listItem","name":"Home"}},{"@type":"ListItem","@id":"http:\/\/www.stuartroberts.net\/index.php\/2014\/09\/30\/quick-tip-21\/#listItem","position":3,"name":"Add Field with XML","previousItem":{"@type":"ListItem","@id":"http:\/\/www.stuartroberts.net\/index.php\/category\/sharepoint\/#listItem","name":"SharePoint"}}]},{"@type":"Person","@id":"http:\/\/www.stuartroberts.net\/#person","name":"Stu","image":{"@type":"ImageObject","@id":"http:\/\/www.stuartroberts.net\/index.php\/2014\/09\/30\/quick-tip-21\/#personImage","url":"https:\/\/secure.gravatar.com\/avatar\/503cb376bab10c66a6bde71d1514dcab2eab4ec44a2f82ef597ca87af61bf1cd?s=96&d=retro&r=g","width":96,"height":96,"caption":"Stu"}},{"@type":"Person","@id":"http:\/\/www.stuartroberts.net\/index.php\/author\/admin\/#author","url":"http:\/\/www.stuartroberts.net\/index.php\/author\/admin\/","name":"Stu","image":{"@type":"ImageObject","@id":"http:\/\/www.stuartroberts.net\/index.php\/2014\/09\/30\/quick-tip-21\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/503cb376bab10c66a6bde71d1514dcab2eab4ec44a2f82ef597ca87af61bf1cd?s=96&d=retro&r=g","width":96,"height":96,"caption":"Stu"}},{"@type":"WebPage","@id":"http:\/\/www.stuartroberts.net\/index.php\/2014\/09\/30\/quick-tip-21\/#webpage","url":"http:\/\/www.stuartroberts.net\/index.php\/2014\/09\/30\/quick-tip-21\/","name":"Quick Tip #21 - Add Field with XML | Stuart Roberts on all things SharePoint","description":"How to programmatically add a SharePoint field to a list using XML.","inLanguage":"en-GB","isPartOf":{"@id":"http:\/\/www.stuartroberts.net\/#website"},"breadcrumb":{"@id":"http:\/\/www.stuartroberts.net\/index.php\/2014\/09\/30\/quick-tip-21\/#breadcrumblist"},"author":{"@id":"http:\/\/www.stuartroberts.net\/index.php\/author\/admin\/#author"},"creator":{"@id":"http:\/\/www.stuartroberts.net\/index.php\/author\/admin\/#author"},"datePublished":"2014-09-30T17:18:17+01:00","dateModified":"2026-10-16T16:54:23+01:00"},{"@type":"WebSite","@id":"http:\/\/www.stuartroberts.net\/#website","url":"http:\/\/www.stuartroberts.net\/","name":"Stuart Roberts on all things SharePoint","inLanguage":"en-GB","publisher":{"@id":"http:\/\/www.stuartroberts.net\/#person"}}]},"og:locale":"en_GB","og:site_name":"Stuart Roberts on all things SharePoint |","og:type":"article","og:title":"Quick Tip #21 - Add Field with XML | Stuart Roberts on all things SharePoint","og:description":"How to programmatically add a SharePoint field to a list using XML.","og:url":"http:\/\/www.stuartroberts.net\/index.php\/2014\/09\/30\/quick-tip-21\/","article:published_time":"2014-09-30T16:18:17+00:00","article:modified_time":"2026-10-16T15:54:23+00:00","twitter:card":"summary","twitter:site":"@SharePointStu","twitter:title":"Quick Tip #21 - Add Field with XML | Stuart Roberts on all things SharePoint","twitter:description":"How to programmatically add a SharePoint field to a list using XML.","twitter:creator":"@SharePointStu"},"aioseo_meta_data":{"post_id":"1724","title":"Quick Tip #21 - Add Field with XML | #site_title","description":"How to programmatically add a SharePoint field to a list using XML.","keywords":[{"label":"SharePoint","value":"SharePoint"},{"label":"SPS","value":"SPS"},{"label":"SP","value":"SP"},{"label":"AddFieldAsXml","value":"AddFieldAsXml"}],"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","local_seo":null,"limit_modified_date":false,"created":"2021-08-03 13:46:14","updated":"2026-10-16 17:08:08","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":{"faqs":[],"keyPoints":[],"schemas":[],"titles":[],"descriptions":[],"socialPosts":{"email":{"subject":"","preview":"","content":""},"linkedin":[],"twitter":[],"facebook":[],"instagram":[]}},"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"http:\/\/www.stuartroberts.net\/\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"http:\/\/www.stuartroberts.net\/index.php\/category\/sharepoint\/\" title=\"SharePoint\">SharePoint<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tAdd Field with XML\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"http:\/\/www.stuartroberts.net\/"},{"label":"SharePoint","link":"http:\/\/www.stuartroberts.net\/index.php\/category\/sharepoint\/"},{"label":"Add Field with XML","link":"http:\/\/www.stuartroberts.net\/index.php\/2014\/09\/30\/quick-tip-21\/"}],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1724","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/comments?post=1724"}],"version-history":[{"count":2,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1724\/revisions"}],"predecessor-version":[{"id":1990,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1724\/revisions\/1990"}],"wp:attachment":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/media?parent=1724"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/categories?post=1724"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/tags?post=1724"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}