Don’t you just love it when you’re slaving away at something that should be pretty straight forward but you just can’t figure it out? Well I just had one of those breakthrough moments and thought I’d share. I spent almost the entire day yesterday searching and trying different ways to add sub folders to Document Libraries programmatically to no avail. I was seriously pulling my hairs out. And then just 30 mins ago, I came across this blog post and now I can go take a 3 hour lunch. Here’s my variation of the code:

private void AddFolders(SPList list, SPWeb web)
{

String url = list.RootFolder.ServerRelativeUrl.ToString();

SPFolderCollection folders = web.GetFolder(url).SubFolders;

folders.Add(“Yay this works”);

}

Long live the blog!

Advertisement