Thursday, November 22, 2007

Adding a folder to a Sharepoint list

From http://blogs.msdn.com/adamhems/archive/2007/08/30/progammatically-adding-folders-to-a-sharepoint-list.aspx

string siteUrl = "http://sample.development.com/sales/prospects";

string listName = "Shared Documents";

SPSite siteCollection = new SPSite(siteUrl);
SPWeb site = siteCollection.OpenWeb();
SPList list = site.Lists[listName];

SPListItem folder = list.Items.Add(list.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder, null);

if (folder != null)
{
folder["Name"] = "NameofFolder";
folder.Update();
}

No comments: