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
using (ClientContext ctxObj = new ClientContext("http://sp2013/")) | |
{ | |
Web objSite = ctxObj.Web; | |
ctxObj.Load(objSite); | |
ctxObj.ExecuteQuery(); | |
//User ClaimID would be ----i:0#.f|membership|domain\username | |
/* | |
i:0#w| => | |
i = identity | |
# = user login name | |
w = Windows | |
i:0#.f => | |
f = membership provider name | |
*/ | |
User objUser = objSite.EnsureUser("i:0#.f|membership|" + userId); | |
ctxObj.Load(objUser); | |
ctxObj.ExecuteQuery(); | |
FieldUserValue objUserValue = new FieldUserValue(); | |
objUserValue.LookupId = objUser.Id; | |
List objListItems = objSite.Lists.GetByTitle("MyList"); | |
Microsoft.SharePoint.Client.ListItem objItem = objListItems.AddItem(new ListItemCreationInformation()); | |
objItem["UserName"] = objUserValue; | |
objItem.Update(); | |
ctxObj.ExecuteQuery(); | |
} |