Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

In document library, I've some documents with version history. In C#, can I get all the version history of document and update the user?

The version history of a document is like below:

Data                Modified By

doc1 changed        User X
some text           User X

Now in C# can I update the Modified By user value with another user?

Thanks in advance

share|improve this question
    
Just to confirm. You want to change the modified by attribute on all the version of the item so after the update even the old version will show the edited "modified by" user? –  SPArchaeologist Oct 22 '12 at 6:46
add comment

2 Answers 2

SPSite site = new SPSite("http://sharepointsite/subsite");
SPWeb web = site.OpenWeb();
SPList list = web.Lists["My List"];
web.AllowUnsafeUpdates = true;
foreach (SPListItem item in list.Items)
{
  item["Modified"] = "Set the date";
  item["Created"] = "Set the date";
  item["Editor"]="itemCreatedUser";
  item.UpdateOverwriteVersion();
}

Hope this helps!

share|improve this answer
add comment

If you call SPListItem.Update() in code I believe that changes the Modified By value to whichever user triggered the code (while SystemUpdate() does not).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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