We faced a scenario where we need to update the prefix for document Id settings for more numbers of site collection in SharePoint Site through code. After some investigation, I figured out the code and thought of sharing it. Here is the code:

Using C# code

  • Add the following references.

    • Microsoft.SharePoint.dll
    • Microsoft.Office.DocumentManagement.dll

  • Add the following namespaces.

    • Using Microsoft.SharePoint;
    • Using Microsoft.Office.DocumentManagement;
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.SharePoint;
  6. using Microsoft.Office.DocumentManagement;
  7. namespace ConsoleAppChangeDocPrefix
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. SPSite site = new SPSite("http://serverName:2085/");
  14. DocumentId.SetDefaultProvider(site);
  15. DocumentId.EnableAssignment(site, "sivaprefix", true, true, true, false);
  16. site.Dispose();
  17. }
  18. }
  19. }
id

Reference :
https://msdn.microsoft.com/EN-US/library/office/ee580557.aspx