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.