Folders can be added under a list or under another
folder and the way of adding in each case is very similar. Below another
example of sample functions.

 
public SPFolder AddFolder(SPList parentList, String title)
{
    // Enable
folder creation on the list
    parentList.EnableFolderCreation
= true; 

    // Add folder
    SPListItem
listItem = parentList.Folders.Add("", SPFileSystemObjectType.Folder);
    listItem["Name"]
= title;

   // Update
   listItem.Update();

   // Return
   return
listItem.Folder;
}

public SPFolder
AddFolder(SPFolder folder, String title)
{
    // Add
    SPFolder
newFolder = folder.SubFolders.Add(title); 

    // Return
    return
newFolder;
}

 

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here