Skip to content

Proxies-free.com: 100% Free Daily Proxy Lists Every Day!

Get Free Proxies Every Day

sharepoint online – Using CSOM can i ensure the user using the login user id instead of the login username

I have the following CSOM code inside my remote event receiver:

ListItem listItem = context2.Web.GetList(context2.Web.ServerRelativeUrl + "/lists/Assets").GetItemById(listItemID);
context2.Load(listItem);
context2.ExecuteQuery();
FieldUserValue creator = listItem("Author") as FieldUserValue;

listItem.BreakRoleInheritance(false, false);
listItem.RoleAssignments.Add(context2.Web.EnsureUser(creator.LookupValue), new RoleDefinitionBindingCollection(context2) { contributeDef });

The above code will get a list item >> assign the author of the item inside the listitem permission. The code will work on 99% of the cases.. but we face this case:-

  1. there is an internal user named user.ABC
  2. there is another external user named also user.ABC

So my above code will always select the internal username, even if the author was the external user.

So can I improve my code by passing the user id to the EnsureUser method? or another way to assign the Author of a list item to the list item permission?

Author AdminPosted on January 12, 2021Categories ArticlesTags csom, ensure, login, online, Sharepoint, user, username

Post navigation

Previous Previous post: postgresql – postgres query performance
Next Next post: linux – How to stop/disable grafana server starting on boot?
Proxies-free.com: 100% Free Daily Proxy Lists Every Day! Proudly powered by WordPress

DreamProxies - Cheapest USA Elite Private Proxies 100 Private Proxies 200 Private Proxies 400 Private Proxies 1000 Private Proxies 2000 Private Proxies ExtraProxies.com - Buy Cheap Private Proxies Buy 50 Private Proxies Buy 100 Private Proxies Buy 200 Private Proxies Buy 500 Private Proxies Buy 1000 Private Proxies Buy 2000 Private Proxies ProxiesLive Proxies-free.com New Proxy Lists Every Day Proxies123