Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.