This issue seems to have come up time and time again, but unfortunately with no solution.

Basically I have a solution where I use CSOM to upload a document.

The code I have is like this

                p.ModifiedBy.ID = _sp.CurrentUser.Id;
                p.Modified = DateTime.Now;
                p.ModifiedByWinframe = u.getWinframe();

                spFile.CheckIn("Uploaded By xxxxxxxx", CheckinType.MinorCheckIn);

There is more above but the basics are that I have a mapper (based on https://sennitspmapper.codeplex.com/) that takes the fields and then can map and unmap them to list items.

So in this example I'm trying to map the modified by fields to the list item and then update.

The modified by fields are 'Modified_x0020_By' 'Editor' and 'Modified' But whatever I do when I CheckIn it resets them to the AppPool user that the MVC application is running on.

I've tried things like this

var modifiedByField = new ListItemFormUpdateValue
                    FieldName = CesaDocument.ModifiedByWinframe_Field,
                    FieldValue = u.getWinframe()

                //try again to fix the author/Editor or CreatedBy/ModifiedBy CSOM 2013
                var updatedValues = new List<ListItemFormUpdateValue> { modifiedByField };
                lstItem.ValidateUpdateListItem(updatedValues, true);

But 2013 doesn't seem to have ValidateUpdateListItem even though the docs say it does. Currently working on Micrsoft.SharePoint.Client 15.0.0

I had a bash at using the JavaScript REST Api through c# and http requests, but no dice. Can't see anything glaringly obvious in the web services.

Is this even possible? In the past I've created a web service as a sharepoint solution and then use that to modify the fields.

Any other ideas?

UPDATE Could a solution be to have a separate app pool running as ApplicationPoolIdentity and somehow have that upload the file? Or change the appPool or is that just insanity!?

UPDATE This is how I load the code, I'm using the mapper again to get the list item into a nice object.

            List siteUserInfoList = this.Web.SiteUserInfoList;

            var q = Camlex.Query().Where(x => (string)x["Name"] == HttpContext.Current.User.Identity.Name);
            IEnumerable<ListItem> itemColl = this.LoadQuery(siteUserInfoList.GetItems(q.ToCamlQuery()));
            this.CurrentUser = itemColl.FirstOrDefault().ProjectToEntity<CesaUser>();
  • 1
    Can you confirm the code _sp.CurrentUser in MVC gives the current logged in user in SharePoint? Or it returns the app pool account? – Ahmad Zia Sep 19 '17 at 5:32
  • 1
    Hi there the _sp object is an extension of the ClientContext object. The _sp.CurrentUser is basically from the SiteUserInfoList - I'll post in the code – Richard Housham Sep 19 '17 at 8:24
  • 1
    @AhmadZia - notify – Richard Housham Sep 19 '17 at 9:15
  • 1
    Can you update created and created by columns. I dont think the solution you are after is possible. Sorry I haven't found any solution but may be someone else updates that post. – Ahmad Zia Sep 19 '17 at 9:50
  • @AhmadZia You can update the created and created by columns that seems possible. It's just the modifed person gets overwritten when you do the checkIn. I did have a way around using Sandbox solution, but SP2013 seems to have sealed that hole. In the end it's looking like a powershell job. On a slight plus, they seems to have solved this on SP365 but we are building an inhouse application and SP365 isn't possible. – Richard Housham Sep 19 '17 at 12:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.