How to create sub folder in List/OneDrive for Business with CSOM

If you want to create a subfolder in already created folder on OneDrive for Business, this code can help you :

Load the web :

Web web = clientContext.Web;
clientContext.Load(web);
clientContext.ExecuteQuery();

Retrieve the parent folder :
The parent folder path can be like : “/Documents/MyParentFolder”

var folder = web.GetFolderByServerRelativeUrl(web.ServerRelativeUrl + parentFolderPath);
clientContext.Load(folder);

Add the folder to the parent :

folder = folder.Folders.Add(folderName);
clientContext.ExecuteQuery();
Advertisements
This entry was posted in OneDrive, SharePoint. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s