Creating a folder in a SharePoint list with Content Types

Posted on July 3, 2012 by

0


This potentially simple task is not as easy as I expected, and I ran into a rather special case which I could not find documented anywhere else, hence this post.

In general terms, SharePoint Steve’s post (http://www.sharepointsteve.com/2010/02/creating-a-folder-in-a-sharepoint-list-and-adding-items-to-it-programatically/) and the useful comments cover off all the common bases, and I would recommend you to start there.

However, even with that, I could not get this to work.

I was creating a custom list that allowed new content types to be added to it (programmatically), and when a new content type was added it would automatically create a new folder for all items that were created using that particular content type. There was a bit more to it in terms of approval, security and event handlers, but those are the salient details.

I decided to use the content type name as the folder name – it was unique and made a clear link between the folder and the content type when browsing the list.

However, that was my downfall; although I can’t find it documented anywhere (any pointers here would be appreciated) you cannot have a folder in a list with the same name as a content type in that list.

The reason is that when you enable content types, SharePoint creates a hidden folder for each content type (with, you’ve guessed it, the content type name as the folder name) that contains resources associated with the content type.

In my case this was no biggy as I was in control of the folder names and simply changed the folder names slightly to make sure they were different from the content type names.

Hope this helps someone out – it took a considerable effort to figure it out and would be nice to think it helps others avoid the same pain!

Advertisements
Tagged: ,
Posted in: SharePoint 2010