Friday, March 4, 2016

Setting permission for a library to a user using CSOM

            string siteURL = "<SITEURL>";
            ClientContext context = new ClientContext(siteURL);
            List list = context.Web.Lists.GetByTitle("<LIBRARYNAME>");
            User user = context.Web.EnsureUser(@"<DOMAIN\USERNAME>");
            list.BreakRoleInheritance(true, false);
            RoleDefinition roleDefinition = context.Web.RoleDefinitions.GetByName("<PERMISSION LEVEL>");
            RoleDefinitionBindingCollection collRoleDefinitionBinding = new RoleDefinitionBindingCollection(context);
            collRoleDefinitionBinding.Add(roleDefinition);
            list.RoleAssignments.Add(user, collRoleDefinitionBinding);
            context.ExecuteQuery(); 

No comments:

Post a Comment

How to launch a document by clicking a link to the file?

Word: <a href='ms-word:ofe|u|path/to/web/word/document.docx'>Link to document</a> Excel: <a href='ms-excel:o...