0
votes

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.GetContextSite(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

enter image description here

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

2
turn off the custom errors (in web.config) for your web application to see the actual error. - Stefan

2 Answers

1
votes
  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.
1
votes

Try adding

props.Add("HTML_x0020_File_x0020_Type", "SharePoint.DocumentSet");  

to the properties hashset that gest passed in to DocumentSet.Create method.