开发者

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

Creating Document set programatically in sharepoint 2010

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


  1. First of all, turn off custom errors, like the screenshots tells you.
  2. Then replace your catch of SPException with a catch of all Exceptions.
  3. Even better yet, test code like this in a separate console app, not right inside handlers.
  4. 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.
  5. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜