Today I had a requirement to add folders programmatically to the default ‘Site Collection Images’ document library. Its quite simple and can easily be achieved with few lines of code. Here is a method of how to do that:
//Remember Document library is also a list in SharePoint String url = site.Lists["Site Collection Images"].RootFolder.ServerRelativeUrl.ToString(); SPFolderCollection folders = site.GetFolder(url).SubFolders; //Create new folder folders.Add("Newfolder");
You can use the same code to create folders/subfolders in any custom document library as well.
You might be interested in:
Thanks for the post, i need to know how to add folder to “Site collection images” from specific conetnt type associated already to the Library, suppose we add special kind of conetnt type “Galery Folder” .. so how to add new folder to the Images Library.
Bingo !!! i was loking 4 exact thing.
tanX pro
Thank you, sorry to ask, but would i add code to have this function automated.. Basically I was to insure that folders A B C D E are always created in this specific portal, when new children portals are created.
[...] to the sharepoint libararies, list etc..but I like the kind of approach praveen takes in this post. I am using the same with no issues here is the code which I am [...]
couldn’t you just do:
SPFolderCollection collection = site.Lists["Site Collection Images"].RootFolder.SubFolders;
?
Juan, seems like it should work but I haven’t tried it. I will give it a try and will update the post accordingly.
Thanks for visiting my blog.
-Praveen