示例#1
0
        //gavdcodeend 12

        //gavdcodebegin 13
        static void SpCsCsomUpdateUserSecurityRoleInList(ClientContext spCtx)
        {
            Web  myWeb  = spCtx.Web;
            List myList = myWeb.Lists.GetByTitle("NewListCsCsom");

            User myUser = myWeb.EnsureUser(ConfigurationManager.AppSettings["spUserName"]);
            RoleDefinitionBindingCollection roleDefinition =
                new RoleDefinitionBindingCollection(spCtx);

            roleDefinition.Add(myWeb.RoleDefinitions.GetByType(RoleType.Administrator));

            RoleAssignment myRoleAssignment = myList.RoleAssignments.GetByPrincipal(myUser);

            myRoleAssignment.ImportRoleDefinitionBindings(roleDefinition);

            myRoleAssignment.Update();
            spCtx.ExecuteQuery();
        }
示例#2
0
        //gavdcodeend 22

        //gavdcodebegin 23
        static void SpCsCsomUpdateUserSecurityRoleInWeb()
        {
            string myWebFullUrl = ConfigurationManager.AppSettings["spUrl"] +
                                  "/NewWebSiteModernCsCsom";
            ClientContext spCtx = LoginCsom(myWebFullUrl);

            Web myWeb = spCtx.Web;

            User myUser = myWeb.EnsureUser(ConfigurationManager.AppSettings["spUserName"]);
            RoleDefinitionBindingCollection roleDefinition =
                new RoleDefinitionBindingCollection(spCtx);

            roleDefinition.Add(myWeb.RoleDefinitions.GetByType(RoleType.Administrator));

            RoleAssignment myRoleAssignment = myWeb.RoleAssignments.GetByPrincipal(
                myUser);

            myRoleAssignment.ImportRoleDefinitionBindings(roleDefinition);

            myRoleAssignment.Update();
            spCtx.ExecuteQuery();
        }