{"id":1415,"date":"2015-04-02T12:24:32","date_gmt":"2015-04-02T11:24:32","guid":{"rendered":"http:\/\/blog.repsaj.nl\/?p=1415"},"modified":"2025-03-04T20:54:42","modified_gmt":"2025-03-04T19:54:42","slug":"o365-enable-document-id-and-set-prefix-via-csom","status":"publish","type":"post","link":"http:\/\/blog.repsaj.nl\/index.php\/2015\/04\/o365-enable-document-id-and-set-prefix-via-csom\/","title":{"rendered":"[O365] Enable document ID and set prefix via CSOM"},"content":{"rendered":"<p>Ok, I agree I&#8217;m late to the party introducing the [O365] tag in the title of this post. And I&#8217;ve got quite some blogposts already which also apply to Office 365.\u00a0But to emphasize there is little difference in using CSOM either on premises or online, I thought this would be a good time to switch. And mentioning you&#8217;re doing Office 365 project is all hip and happening anyway, so here it is.<\/p>\n<p>This simple post gives you some code which shows how to set the Document ID settings via CSOM. It&#8217;s not hard, but since I haven&#8217;t been able to find any blogs out there which cover this, I thought I&#8217;d take the opportunity.<!--more--><\/p>\n<p>You&#8217;ll find that the client side\u00a0object models do not give you a way of directly changing settings related to the Document ID feature. In particular, this window in your site settings (Site Collection Administration =&gt; Document ID Settings):<\/p>\n<p><a href=\"http:\/\/blog.repsaj.nl\/wp-content\/uploads\/2015\/04\/documentid.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1416\" src=\"http:\/\/blog.repsaj.nl\/wp-content\/uploads\/2015\/04\/documentid.png\" alt=\"documentid\" width=\"615\" height=\"249\" srcset=\"http:\/\/blog.repsaj.nl\/wp-content\/uploads\/2015\/04\/documentid.png 615w, http:\/\/blog.repsaj.nl\/wp-content\/uploads\/2015\/04\/documentid-300x121.png 300w\" sizes=\"(max-width: 615px) 100vw, 615px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Well, as with most of the settings you cannot find in the object model, they are actually stored in the property bag of your site collection. <a href=\"http:\/\/samer365.com\/2013\/07\/22\/sharepoint-2013-csom-property-bag-properties\">This blog<\/a> gives an overview of the properties there are, and if you want to find out which properties are on your sites, you can use the <a href=\"http:\/\/spcb.codeplex.com\">SharePoint Client Browser<\/a> project by Bram de Jager for that.<\/p>\n<p>The properties you&#8217;ll want to set are:<\/p>\n<ul>\n<li>docid_enabled; the &#8220;Assign Document IDs&#8221; checkbox<\/li>\n<li>docid_msft_hier_siteprefix; the prefix you set for the document ID feature<\/li>\n<\/ul>\n<p>And with that knowledge, setting them is easy:<\/p>\n<pre class=\"prettyprint lang-cs\">using (ClientContext context = new ClientContext(url))\r\n{\r\n    Web mainWeb = context.Web;\r\n    var props = mainWeb.AllProperties;\r\n    props[\"docid_msft_hier_siteprefix\"] = \"MYPREFIX\";\r\n    props[\"docid_enabled\"] = \"1\";\r\n    mainWeb.Update();\r\n    context.ExecuteQuery();\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Ok, I agree I&#8217;m late to the party introducing the [O365] tag in the title of this post. And I&#8217;ve got quite some blogposts already which also apply to Office 365.\u00a0But to emphasize there is little difference in using CSOM either on premises or online, I thought this would be a good time to switch.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[34],"tags":[60,129,130,39],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3KFR1-mP","_links":{"self":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/posts\/1415"}],"collection":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/comments?post=1415"}],"version-history":[{"count":1,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/posts\/1415\/revisions"}],"predecessor-version":[{"id":2887,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/posts\/1415\/revisions\/2887"}],"wp:attachment":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/media?parent=1415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/categories?post=1415"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/tags?post=1415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}