Create Folder in SharePoint using CSOM

The example in this topic show how to use CSOM to Create Folder in SharePoint

  • using Microsoft.SharePoint.Client;
  • using System.Linq;
  •  
  • using (ClientContext clientContext = new ClientContext("http://MyServer/sites/MySiteCollection"))
  • {
  • // clientcontext.Web.Lists.GetById - This option also can be used to get the list using List GUID
  • // This value is NOT List internal name
  • List byTitle = clientcontext.Web.Lists.GetByTitle("New list");
  •  
  • // New object of "ListItemCreationInformation" class
  • ListItemCreationInformation listItemCreationInformation = new ListItemCreationInformation();
  •  
  • // Below are options.
  • // (1) File - This will create a file in the list or document library
  • // (2) Folder - This will create a foder in list(if folder creation is enabled) or documnt library
  • listItemCreationInformation.UnderlyingObjectType = FileSystemObjectType.Folder;
  •  
  • // This will et the internal name/path of the file/folder
  • listItemCreationInformation.LeafName = "Folder Name";
  •  
  • ListItem listItem = byTitle.AddItem(listItemCreationInformation);
  •  
  • // Set folder Name
  • listItem["Title"] = "Folder Name";
  •  
  • listItem.Update();
  • clientcontext.ExecuteQuery();
  • }

Thank you for reading this article. This code was tested in SharePoint 2013


© 2019 Code SharePoint