How to create a Modern Document Library in SharePoint 2010/2013/Online using CSOM?

Hello SharePointers,

Below is the CSOM to create a document library in Sharepoint online using CSOM . ListExperience.NewExperience is the property, we need to  set it up.

var SiteURL = @”https://myssharepoint.com/sites/”;
var mylogin = “Laks@***.onmicrosoft.com”;
var mypassword = “****”;

var securePassword = new SecureString();

foreach (char c in password)
{
securePassword.AppendChar(c);
}
SharePointOnlineCredentials onlineCredentials = new SharePointOnlineCredentials(mylogin, mypassword);

ClientContext ctx = new ClientContext(SiteURL );
ctx.Credentials = onlineCredentials;
Web web = ctx.Web;

ListCreationInformation lci = new ListCreationInformation();
lci.Description = “Test Library”;
lci.Title = “Library”;
lci.TemplateType = 101;

List newLib = ctx.Web.Lists.Add(lci);
ctx.Load(newLib);
ctx.ExecuteQuery();

var createLibrary = ctx.Web.Lists.GetByTitle(“Library”);
createLibrary.ContentTypesEnabled = true;
createLibrary.ListExperienceOptions = ListExperience.NewExperience;
createLibrary.Update();
ctx.ExecuteQuery();

Happy SharePointing 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *