In my last article on SharePoint 2010 creating custom document Id provider we looked at how to create a sample document id provider. Last time I checked SharePoint 2010 SDK – there is nicely put sample of custom document ID provider but the deployment PowerShel script – doesn’t work. It returns error no matter how you try to tweak it. Not having a way to deploy your custom provider makes it kind of hard to test its functionality and try things out. Fortunately, there is an alternative way to deploy your provider using a feature receiver.
1. Create new SharePoint solution or add a new feature to an existing solution.
2. In your Visual Studio project where you have your custom provider class copy the content of a provider class to a new class in your solution.
3. Add an event receiver to your newly created feature and replace the FeatureActivated methd with the following:
using Microsoft.Office.DocumentManagement;
///
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{SPSite site = (SPSite)properties.Feature.Parent;
DocumentId.SetProvider(site, new MyDocumentIdProvider());
}
In here, MyDocumentIdProvider, is the class representing my custom document ID provider.
Here is what your FeatureDeactivated might look like:
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
SPSite site = (SPSite)properties.Feature.Parent;
DocumentId.SetDefaultProvider(site);
}
Essentially, here you set the default provider as a current provider. Good Luck!