I'm having difficulty creating a document set programmatically from a custom list item edit form. (My goal is to create a document set linked to this list item) Instead of creating an item of content type "Document Set" I am getting a folder, albeit with the type icon that you would expect from a Document Set. When I click on this wannabe-document set-folder I get 'page not found' error. If I edit it and change the content type manually it opens fine.
Here's my code: Please note, I am getting the content type from the list, not the web, which typically gives programmers this error.
private void LaunchInvestigation()
{
//Get current ListItem information
SPListItem callLogItem = SPContext.Current.ListItem;
string title = Convert.ToString(callLogItem["Title"]);
DateTime startDate = Convert.ToDateTime(callLogItem["StartDate"]);
/// Find the library where Document Set will be created.
SPWeb currentWeb = SPContext.Current.Web;
SPDocumentLibrary list = (SPDocumentLibrary)currentWeb.Lists["Investigation Log"];
//Find the Content Type for the Document Set you're creating
//string docSetName = "Document Set";
SPContentType docSetName = list.ContentTypes["Document Set"];
//You can use a hashtable to populate properties of the document set
var docsetProperties = new Hashtable { { "DocumentDesciption", string.Format("Document Set for {0}", title) }, { "Name", title } };
DocumentSet documentSet = DocumentSet.Create(
list.RootFolder,
title,
list.ContentTypes.BestMatch(docSetName.Id),
docsetProperties,
true);
callLogItem["InvestigationDocuments"] = string.Format("{0}, {1}", documentSet.WelcomePageUrl, "Documents");
callLogItem.Update();
}