DocumentSets – DocumentSet.Create() and the properties hashtable

I’ve been working on a small utility to do some mass document set creation for a couple of custom content types I created that inherit from the DocumentSet content type. This is a pretty easy thing to do. You just need to call the DocumentSet.Create() method, pass in the folder to create in, document set name, the content type, a hash table of properties for your new document set, and voila, you’re done. Well, not so fast my friend. Everything was working great, except for the whole hash table of properties part, which was important to me, and probably most folks. I spent entirely too much time trying to figure out why my properties weren’t getting set.

I finally broke down and looked at the source for the DocumentSet.Create method. After a quick review, and a little testing, it quickly became evident that in your properties hash table, the key of your key and value pair, needs to be the static name of the field you want to set, not the display name. Some of you may be asking great, how do I figure out the static name. It’s pretty easy. The SPField class has a public property called StaticName. You can write a couple of lines of code to figure that out. Also, you can use a tool called SharePoint manager, to browse to your site collection, look at your field and check the properties. This is a very handy tool for developers.

An example of the static name for a field called “Test Field” would likely be “Testx0020Field”.

Since, we (Microsoft) didn’t bother to document this anywhere I created this blog post, and will work to get this updated through the internal channels.

DocumentSet.Create –
SPField.StaticName – 
SharePoint Manager – 

PS – If you’re trying to set a field type of user/group, you’ll need to pass in an SPUser.

Comments (2)

  1. Nils says:

    Great, thanks! – I really appreciate your additional documentation….

    I am trying to add a custom new form of a document set inheriting content type. Which sadly is very hard to accomplish. Especially I am not able to save Integer values passed down from SPFormField Controls into the DocumentSet hashtable… is there any way to do this?

    I tried the following:

    var angebotsNrFormField = VertriebsprojektPanel.FindControl("AngebotsNrFormField") as FormField;

    props.Add("Angebots-Nr", kundeFormField.Value);  

    Greetings from germany,


  2. Flo says:

    thx for your ps.. saved me a lot of time 🙂