2

We have document libraries in Sharepoint 2010 with incorrect modified dates and users (they were imported from somewhere). I thought, I could correct them with Powershell, but it does not work the way I tried and I cannot figure out what is wrong.

It is easy for list items:

$item["Editor"] = $newuser
$iten["Modified"] = $newdate
$item.update()

I thought, I could adapt this to versions. I can read the properties, but when I try to assign a new value, it throws an error:

Unable to index into an object of type Microsoft.SharePoint.SPListItemVersion.
At line:1 char:10
+ $version[ <<<< "Modified"]=$newdate
+ CategoryInfo          : InvalidOperation: (Modified:String) [], RuntimeE
xception
+ FullyQualifiedErrorId : CannotIndex

What am I doing wrong? Is there another way to change these values?

  • Can you share what code you used to update versions. Moreover, it should not be $item.update(). It should rather be $item.SystemUpdate() – Nadeem Yousuf Mar 11 '15 at 13:57
  • I have not had the chance to update (yet). The error is thrown before. I cannot even assign the value. – EGwalden Mar 11 '15 at 14:23
1

You cannot change item version properties as SPListItemVersion.this[string] indexer is read only. That is, whereas this code is legal:

SPListItem item = list.GetItemById(1);
item["X"] = "a";

The below code will throw error:

Property or indexer 'Microsoft.SharePoint.SPListItemVersion.this[string]' cannot be assigned to -- it is read only

SPListItem item = list.GetItemById(1);                
SPListItemVersionCollection versions = item.Versions;
foreach(SPListItemVersion version in versions)
{
    version["Modified"] = new DateTime(2014, 1, 1);
}

Moreover, properties of SPListItemVersion are read only as well, like SPListItemVersion.CreatedBy

  • Is there no way to change these values? – EGwalden Mar 12 '15 at 9:10
  • I am afraid there isn't any way of doing this. At least I couldn't find one. – Nadeem Yousuf Mar 12 '15 at 9:13
  • how about re-upload the documents and change the modified date of each one before uploading the next document – Mike Jul 3 '18 at 21:16

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.