I want to change 'Modified By' column value of a file that is being uploaded using Client Object Model in SharePoint 2013. The problem is that the version of the file is changing. Kindly help me. The code that I am using is:

using (System.IO.Stream fileStream = System.IO.File.OpenRead(m_strFilePath))
    Microsoft.SharePoint.Client.File.SaveBinaryDirect(m_clientContext, str_URLOfFile, fileStream, true);
    Microsoft.SharePoint.Client.File fileUploaded = m_List.RootFolder.Files.GetByUrl(str_URLOfFile);
    User user1 = m_Web.EnsureUser("User1");
    User user2 = m_Web.EnsureUser("User2");
    ListItem item = fileUploaded.ListItemAllFields;
    item["UserDefinedColumn"] = "UserDefinedValue1";
    item["Title"] = "UserDefinedValue2";
    item["Editor"] = user1;
    item["Author"] = user2;
    fileUploaded.CheckIn(string.Empty, CheckinType.OverwriteCheckIn);
  • 3
    I don't think you can do this with client-side code -- every time you update an item with client-side code, you're making a modification as the currently logged in user.. then even if you could edit the 'Modified By' field, the internal item modified event would fire and update the 'Modified By' field again with whoever you are logged in as. I would probably add a seperate field for this situation (we use one called 'Document Owner' to signify who is responsible for a document, even when not the person that last modified it) – John-M Oct 1 '14 at 14:07
  • That's the point with client-side: if that was possible, it would be a huge breach, since, by definition, the client-side OM is available for any client... That's exactly why, as a developer, I definetely prefer server-side approaches where all gates are open: it's more "risky", but either our customers trust us (developers) or they don't hire us! :) – Evariste Nov 14 '15 at 9:09
  • According to technet it is possible. But perhaps the CheckIn action is overriding the modified by. – Erin L Dec 23 '15 at 16:34
  • Yeah the checkIn overrides it - doesn't seem to matter what you do. Even checking back out and trying to overwrite the previous version (using OverwriteCheckIn). It's just not having it. I think the web services might be the only way. – Richard Housham Jan 13 '17 at 13:44

You can modify with powershell:

$web = Get-SPWeb "site URL"

$list = $web.Lists["List Name"]

foreach($item in $list.Items){

    $itemAtual["Created"] = "Created Date"
    $itemAtual["Author"] = "Author ID"

| improve this answer | |
  • 1
    This is server side programming (Since it uses 'SP' in 'Get-SPWeb'). Can you give a solution in client side programming? – talib2608 Dec 18 '13 at 5:58
  • I have noted that when every there is one item.Update(); , the version gets increased by one. I have also noted item["_UIVersionString"] = "1.0"; doesn't have any effect. – talib2608 Dec 18 '13 at 9:29
  • Client side I never get sucessefull – Diego Hillesheim Dec 19 '13 at 11:01

I think this Should work.

ListItem item = fileUploaded.ListItemAllFields; 
listItem["Modified"] = Convert.ToDateTime(modifiedDate);
listItem["UserDefinedColumn"] = "UserDefinedValue1"; 
listItem["Title"] = "UserDefinedValue2"; 
listItem["Editor"] = user1; 
listItem["Author"] = user2; 
file.CheckIn(comments, CheckinType.OverwriteCheckIn);
| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.