Created
November 6, 2017 22:36
-
-
Save AsishP/20a7b264a02b70fd1efa7824ca20287b to your computer and use it in GitHub Desktop.
User not found in SharePoint CSOM code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FieldUserValue authorUser = (FieldUserValue) listItem["Author"]; | |
User author = web.EnsureUser(authorUser.LookupValue); | |
bool byPassAuthorCreation = false; | |
try | |
{ | |
context.Load(author); | |
context.ExecuteQuery(); | |
}catch(Exception ex) | |
{byPassAuthorCreation=true;} | |
//Code to break permissions … | |
if(!byPassAuthorCreation) | |
{ | |
listitem.RoleAssignments.Add(author, new RoleDefinitionBindingCollection(context){web.RoleDefinitions.GetByType(RoleType.Contributor)}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment