Add a new User to the User Information List from the Office365 Active User Panel using Client Object Model C#

This post is about a hidden List of SharePoint, User Information List. In this, the items are the active Office365 users, that have some interaction with this site. For ex. if a user has visited the site, or, the user has been marked in one of the List [like assigned a Task] of the site, or, the user is the administrator then, the user gets automatically added to this List.

By default, the site’s administrator is the only added user to this List. So, if you assign say, a task, to an active user from the Office365 user panel, then, SharePoint automatically adds the user in the User Information List. In my one of the earlier post, https://realmpksharepoint.wordpress.com/2014/01/19/update-a-usermulti-column-value-in-client-object-model-c/, I had demonstrated how to update a UserField SiteColumn say, Attendees for a Calendar item[meeting], with the user id from the web’s SiteUsers. However, we only get the users from the User Information List as the SiteUsers in CSOM.

So how to add a new active user to this List using CSOM? The answer is the EnsureUser method.
It adds the valid user to the site if it’s not already added.

User user = clientContext.Web.EnsureUser("Piyush Singh");
clientContext.Load(user);
clientContext.ExecuteQuery();

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.