in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

Sharepoint Space

It is all about Sharepoint

create folder, subfolder in Sharepoint programically

//Create folder: 
SPDocumentLibrary docLib = GetYourDocumentLibrary("YourSiteName","Pages");
SPListItem newFolder = docLib.Items.Add("",SPFileSystemObjectType.Folder,"first folder")
newFolder.Update();
//Create subfolder: 
SPDocumentLibrary docLib = GetYourDocumentLibrary("YourSiteName","Pages");
SPListItem newFolder = docLib.Items.Add("http://yoursharepointsite/yoursite/pages/first folder",SPFileSystemObjectType.Folder,"first folder")
newFolder.Update();

Only thing needs to mention is Items.Add() function. First parameter is url, when create folder at the root, use "", when create subfolder, you have to provide the full URL including site collection, site, document library name and parent folder name. It took me 1 hour to figure out, hope this post will save your time.

Comments

 

Alex said:

Great and simple post.. thanks :)

February 26, 2008 10:15 AM
 

Georg said:

Thanks, it helps me a lot!

March 18, 2008 6:19 AM
 

MossBoy said:

kool , But your are adding Folder as Item . Here is problem suppose you want Create a folder in taskList . U have workflow which will be strated on item adding event then how you gonna handle it .. the problem is if u create with spfoldercolletion .. it will create folder but it is hidden type ..

August 26, 2008 9:43 AM
 

mingssn said:

MossBoy:

Folder is a special item in SP. For the workflow, if it is a custom workflow, it is quite simple to dectect the item type before start it.

August 26, 2008 1:18 PM

Leave a Comment

(required )  
(optional )
(required )  
Add

Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts