By: Yi Fan Tang
Document Set is a new feature introduced in SharePoint 2010. Today I am going to show you how to copy a document set from one library to another library programmatically. To manipulate the document set objects, we need to use an assembly “Microsoft.Office.DocumentManagement.DocumentSets.dll”. This assembly is out of box. In the In the following example, supposed we need to copy a document set called “Testing” from the “Source” library to the “Target” library.

We basically export the whole document set (including its files) into data stream, and then import those into the target library. This is accomplished by using the “DocumentSet.Export” and “DocumentSet.Import” functions.
using (SPSite site = new SPSite("http://yitangsp2010/sites/dsdemo"))
using (SPWeb web = site.OpenWeb())
{
SPList sourceList = web.Lists["Source"];
SPListItem sourceItem = sourceList.Folders[0];
DocumentSet documentSet = DocumentSet.GetDocumentSet(sourceItem.Folder);
SPList targetList = web.Lists["Target"];
SPContentTypeId contentTypeId = targetList.ContentTypes["Document Set"].Id;
byte[] documentSetData = documentSet.Export();
string documentSetName = documentSet.Item.Name;
SPFolder targetFolder = targetList.RootFolder;
Hashtable properties = sourceItem.Properties;
DocumentSet.Import(documentSetData, documentSetName, targetFolder, contentTypeId, properties, web.CurrentUser);
}

If you get the “DocID: Site prefix not set” error during the “DocumentSet.Import” you can use the following PowerShell command to fix that:
$site = Get-SPSite http://yitangsp2010/sites/dsdemo $properties = $site.RootWeb.Properties $properties["docid_msft_hier_siteprefix"] = "" $properties.Update()
By: Yi Fan Tang