Skip to content

Instantly share code, notes, and snippets.

@AsishP
Created November 6, 2017 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AsishP/20a7b264a02b70fd1efa7824ca20287b to your computer and use it in GitHub Desktop.
Save AsishP/20a7b264a02b70fd1efa7824ca20287b to your computer and use it in GitHub Desktop.
User not found in SharePoint CSOM code
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