a close-up of a building

How to update SharePoint Document Id

What is a SharePoint Document Id?

SharePoint Document ID is a feature in SharePoint that provides a unique identifier for every document in a SharePoint site collection. The Document ID is automatically generated when a document is added to SharePoint and remains the same, even if the document is moved or renamed within the site collection. This helps to ensure that the document can be easily located and referenced, even if its location or name changes.


The Document ID can be used in a variety of ways, including in search results, to reference a specific document, or as a means of linking to a document from another location in SharePoint or in a different application. Additionally, the Document ID can be customized to include additional information, such as the document's author or date of creation. This can help to provide additional context for the document and make it easier to manage and track.

Can SharePoint Document Id be updated programmatically?



The Document Id is stored in three document library fields.


_dlc_DocId = Text Field

_dlc_DocIdUrl = URL Field

_dlc_DocIdPersistId = Boolean Field


To update the value of the Document Id you need to update the first two as follows:


Set-PnPListItem -List "Documents" -Identity 1 -Values @{"_dlc_DocIdUrl" = "/sites/your-site/_layouts/15/DocIdRedir.aspx?ID=1234-1505672353-1, 1234-1505672353-1";"_dlc_DocId" = "1234-1505672353-1"} -UpdateType SystemUpdate


Where 1234-1505672353-1 is the value you'd like to assign as Document ID.



Should I update the _dlc_DocIdPersistId field value too?


It should remain unchanged, i.e. with a value of $false. Whenever the internal SharePoint code finds this attribute set to True, it flips it back to False but skips assigning a new document ID.


Source: SharePoint 2010 : How to retain Document ID while moving documents



Should you ever update SharePoint Document Id programmatically?



The right answer is NO. You should keep the Document ID immutable. However, Microsoft implemented a feature of the Document ID, where the admin can reset the prefixes of a Document ID, which confronts the idea of IDs being unique and immutable. Hey, it is what it is and some clients what these prefixes values synced when a file is moved to a different document library. Of course, "Reset all Document IDs" is a one-time job and has to be manually set by admin every time you'd like to do that, and of course, there is no API that can trigger this event, so why automate it?

It is not all bad. At least the option to update the list item with the proper values is working. The _dlc_DocId and _dlc_DocIdUrl are read-only fields in the list, but when a system update is triggered, the values update.


And don't worry, the new URL in the _dlc_DocIdUrl will not work for some time until the SharePoint search indexes the new values. It looks like the /_layouts/15/DocIdRedir.aspx?ID=<DocumentId> uses search internally to do the proper redirect.