Maybe this was easy for everyone else but I have to admit that this wasn’t easy for me. As you may know I have developed a tool for SharePoint 2010 Site Provisioning in order to enhance the SharePoint development process which wasn’t able to programmatically create folders and subfolder in a document library or list.

So while I tried to change this I had a lot of trouble to achieve my goal.

Programmatically create a folder in a document library

This is the desired result:

I was able to successfully create a folder in a document library using this code:

"/lists/Custom List/Folder1"The folder is created under “Folder1” in “Custom List”…

"/aboutus/lists/Custom List"The folder is created under “Custom List” in a sub site…

"/aboutus/lists/Custom List/Folder1"The folder is created under “Folder1” in “Custom List” in a sub site…

Important: The folder didn’t create for me when my “completeFolderUrl” ended with a slash ‘/’.

Summary

I don’t know if I’m the only one who had problems to programmatically create folders and subfolder in a document library or list but I hope this helps someone else before you bang your head against the wall or table.