The code snippet showing you how you create folder in Office 365 SharePoint Document Library C#.
The code snippet below creates 2 folders, Floder1 and Floder2 in a Document Library name Documents.
static void Main(string[] args)
{
string siteUrl = “https://someone.sharepoint.com/Dev%20Site”;
ClientContext clientContext = new ClientContext(siteUrl);
SecureString securePassword = Login.GetPassword();
clientContext.Credentials = new SharePointOnlineCredentials(“someone@someone.onmicrosoft.com”, securePassword);
Web rootWeb = clientContext.Web;
//Get List
var query = clientContext.LoadQuery(rootWeb.Lists.Where(p => p.Title == “Documents”));
clientContext.ExecuteQuery();
List list = query.FirstOrDefault();
string[] namesArray = new string[] { “Folder1”, “Folder2” };
foreach (string name in namesArray)
{
var folders = list.RootFolder.Folders;
clientContext.Load(folders);
clientContext.ExecuteQuery();
var newFolder = folders.Add(name);
Console.WriteLine(name);
}
//Execute request
clientContext.ExecuteQuery();
}
About the Author:
Similar Content which may interest you:
-
Azure PowerApps using SharePoint Online Data
-
Create a cool CRM for SharePoint and Office 365 with Add-Ins
-
Sway as the new Publishing system in the future?