Creating Document set programatically in sharepoint 2010
I am creating a document set programatically on buttom click event
public void btnCreateDocumentSet_Click(object sender, EventArgs e)
{
try
{
lblError.Text = string.Empty;
SPSecurity.RunWithElevatedPrivileges(() =>
{
using (web = SPControl.GetContextSit开发者_如何学JAVAe(Context).RootWeb)
{
web.AllowUnsafeUpdates = true;
String url = web.Lists[" Tracker"].RootFolder.ServerRelativeUrl.ToString();
SPList list = web.Lists["Tracker"];
Hashtable props = new Hashtable();
props.Add("Number", "item1");
props.Add("Type", "item2");
DocumentSet ds = DocumentSet.Create(list.RootFolder, "NewDocumentSet3", web.ContentTypes["MydocumentSet2"].Id, props, true);
//test
//web.Dispose();
}
}
);
}
catch (SPException ex)
{
lblError.Text = ex.Message;
}
}
I am not getting any exceptions.On button click i am redirected to an error like the following
However the document set named NewDocumentSet3 is created in document library but it looks like a folder(the icon i mean) . when i go to document library->documents tab->New Document I am not getting the document set type .Kindly advise me on this issue. Thanks in advance
- First of all, turn off custom errors, like the screenshots tells you.
- Then replace your catch of SPException with a catch of all Exceptions.
- Even better yet, test code like this in a separate console app, not right inside handlers.
- Look up some resources on the internet on how to debug SharePoint applications. A breakpoint will get you a long way in this particluar situation.
- I am very wary of your list called "[space]Tracker". Looks suspicious to me.
Try adding
props.Add("HTML_x0020_File_x0020_Type", "SharePoint.DocumentSet");
to the properties hashset that gest passed in to DocumentSet.Create method.
精彩评论