Wednesday, August 3, 2011

Create Folder in SharePoint List or Library programmatically

Sharepoint Document Library
=========================
SPList listWorkingDocs = oWeb.Lists.TryGetList("Working Documents");
SPFolder folder = listWorkingDocs.ParentWeb.GetFolder(listWorkingDocs.RootFolder.Url + "/" +"Foldername");
if (!folder.Exists)
{
SPListItem folderWDocs = listWorkingDocs.Folders.Add("", SPFileSystemObjectType.Folder, "foldername");
folderWDocs.Update();
//SPFolderCollection folderColl = listWorkingDocs.RootFolder.SubFolders;
//folderColl.Add(listWorkingDocs.ParentWebUrl + "/" + listWorkingDocs.Title + "/" + "foldername"+ "/");
}

Sharepoint List
==============

SPList listTasks = oWeb.Lists.TryGetList("Tasks");
    SPFolder folder = listTasks.ParentWeb.GetFolder(listTasks.RootFolder.Url + "/" + sMissionName);
     if (!folder.Exists)
       {
           SPListItem folderItem = listTasks.Items.Add();
             folderItem["BaseName"] = sMissionName;
              folderItem["FSObjType"] = "1";
               folderItem.Update();
                }

No comments:

Post a Comment

Followers

Blog Archive