I want to create folder on SharePoint document library using client object model (C#). Below is the code which does that.
ContentTypeCollection listContentTypes = list.ContentTypes;
clientContext.Load(listContentTypes, types => types.Include
(type => type.Id, type => type.Name,
type => type.Parent));
var result = clientContext.LoadQuery(listContentTypes.Where(c => c.Name == "Folder"));
clientContext.ExecuteQuery();
ContentType folderContentType = result.FirstOrDefault();
ListItemCreationInformation newItemInfo = new ListItemCreationInformation();
newItemInfo.UnderlyingObjectType = FileSystemObjectType.Folder;
newItemInfo.LeafName = Foldername;
ListItem newListItem = list.AddItem(newItemInfo);
newListItem["ContentTypeId"] = folderContentType.Id.ToString();
newListItem["Title"] = Foldername;
ewListItem.Update();
clientContext.Load(list);
clientContext.ExecuteQuery();
Now i have thousands of folders to be created on library. So is there any other way i can do this using Bulk operation, so client to server connection will only be called once.
Problem is it is taking too much time to create folder because for each and every folder it will call SharePoint object.