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.