Ecco come aggiungere un folder (SPFolder) ad una lista o document library in SharePoint 2007 (WSS3 - MOSS).

C#

string url = "http://sharepoint2007/Lists/SgartTest";
using (SPSite site = new SPSite(url))
{
  using (SPWeb web = site.OpenWeb())
  {
    SPList list = web.GetList(url);
    //add a folder with name
    string name = string.Format("SgartFolder_{0:yyyyMMddHHmm}", DateTime.Now);
    SPListItem folder = list.Folders.Add(
      list.RootFolder.ServerRelativeUrl
      , SPFileSystemObjectType.Folder
      , name);
    //get and set correct content type (folder)
    SPContentTypeId ctFolder = list.ContentTypes.BestMatch(SPBuiltInContentTypeId.Folder);
    folder[SPBuiltInFieldId.ContentTypeId] = ctFolder;
    folder.Update();
  }
}
Tags:
SharePoint498 SharePoint 2007218
Potrebbe interessarti anche: