Creating SharePoint 2010 custom document ID provider

SharePoint 2010 document center allows you to add new documents to the site and then after they are assigned unique ID – be able to find them by that ID. In past versions the problem was that you have no control on what the resulting ID will end up being.

In SharePoint 2010 – there is no visual way for you to decide what is your ID going to be – however, there is a way to do that through code.

Here is how to create your won custom document ID provider:

1. Using VS 2010 create a new class library.
2. Sing the project and and ensure the version of .NET you’re using is 3.5.
3. Add the following using stamenets:

using Microsoft.Office.DocumentManagement;
using Microsoft.SharePoint;

4. Add main class that inherits from DocumentIDProvider:

public class MyDocumentIDProvider : DocumentIdProvider
{
}

5. Now, add the following 4 methods that will handle the document provider work:

public override string[] GetDocumentUrlsById(SPSite site, string documentId)
{

}

This method will handle the logic of taking the ID passed by the user and resolving this ID to an actual URL. For example if your ID consists of web name and the id of the file – you would have to implement thr logic that will look for an item in the list under certain web.

public override string GenerateDocumentId(SPListItem listItem)
{

}

This is a reverse action method that will give a new ID to an item that has been dropped to the document center. Again, here you’re responsible for coming up with your own ID based on the list item that was passed.

public override string GetSampleDocumentIdText(SPSite site)
{

}

This method will return a sample ID for users to see in the default search box on the site. Here is how default ID looks like:

That’s it. In my next article I will write our a sample provider and describe how to deploy it to the site. Enjoy!

This entry was posted in sharepoint, sharepoint 2010 and tagged , , , , , . Bookmark the permalink.

Comments are closed.