SPOnline Create Document List and Modify Advanced Properties
-
21-12-2020 - |
문제
In my research and coding I can programmatically create a document library/list on 0365 SharePoint Online in this fashion:
using (var ctx = new ClientContext("Http://..."))
{
ctx.Credentials = new SharePointOnlineCredentials("UserName", "SecurePwd");
var list = new ListCreationInformation()
{
Title = "My Title",
Description = "My Desicription",
TemplateType = asDocumentLibrary ? 101 : 100,
QuickLaunchOption = QuickLaunchOptions.On
};
ctx.Web.Lists.Add(list);
ctx.ExecuteQuery();
}
In the above code the advance option of QuickLaunchOption
is a property which I can change, and do.
But there are no other advance options. Do I have to query after the ExecuteQuery
and pull down that newly created list in SPList
form? Or is there a better way to change advance attributes of the list during creation?
해결책
You do not have to execute query after ctx.Web.Lists.Add(list);
. Simply store the list into a variable, and change the settings you need to change. You can do a single ExecuteQuery();
at the end. I wish I had some links to support this, but all I can say is that I've been able to create a list, break role inheritance and add custom role assignments all before calling ExecuteQuery();
in the past:
var listCreationInformation = new ListCreationInformation
{
Title = title,
Description = description,
ListTemplate = listTemplate,
TemplateFeatureId = listTemplate.FeatureId,
TemplateType = listTemplate.ListTemplateTypeKind
};
var list = web.Lists.Add(listCreationInformation);
list.BreakRoleInheritance(false, true);
list.RoleAssignments.Add(owners, new RoleDefinitionBindingCollection(ctx) {contribute});
list.RoleAssignments.Add(members, new RoleDefinitionBindingCollection(ctx) { contribute });
list.RoleAssignments.Add(bhtg, new RoleDefinitionBindingCollection(ctx) { contribute });
ctx.ExecuteQuery();