0
votes

I'm trying to put the current user logged in my MVC 5 application (with windows authentication) into the Author and Editor fields of a new ListItem.

I didn't succeed to just pass the user credentials to the SharePoint Client context, so I tried to edit these two fields instead using SharePoint Client Object Model

using SP = Microsoft.SharePoint.Client;

...

SP.User SPuser = context.Web.EnsureUser(Request.LogonUserIdentity.Name); 
//SP.User SPuser = context.Web.EnsureUser("mydomain\\someuser"); //same result as above
context.Load(SPuser);
context.ExecuteQuery();

SP.FieldUserValue userValue = new SP.FieldUserValue();
userValue.LookupId = SPuser.Id;

SP.ListItem documentLi = documentFile.ListItemAllFields;

...

//We don't want the application pool identity here, but the current user
documentLi["Author"] = userValue;
documentLi["Editor"] = userValue;

documentLi.Update();
context.ExecuteQuery();

It works fine in localhost, but nothing happens when I try it on the server : these two fields keeps the application pool identity.

What did I miss ?

1

1 Answers

0
votes

I found what was the problem : in localhost the application pool identity is my user which has full control on the sharepoint list unlike the application pool identity in IIS (it just had contribute permission), it worked fine once I promoted it with full control as well.