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

I want to update the property vti_author in an item in a SPDocumentLibrary, but it doesn't work. The items original vti_author is the same even after running this script, why?

$spSite = Get-SPSite http://mySite/
$spWeb = $spSite.OpenWeb("News");
$spDocumentLibrary = $spWeb.Lists["Pages"];
$items = $spDocumentLibrary.GetItems();

foreach ($item in $items)
{
    $vtiAuthor = $item.properties["vti_author"];

    if ($vtiAuthor.EndsWith("sp_reader"))
    {

        # Check out 
        $file = $item.File; 
        $file.CheckOut(); 

        # fails - no read only field
        #$item.properties["vti_author"].ReadOnlyField = false;

        $newAuthor = "DOMAIN\user"; 
        $item.properties["vti_author"] = $newAuthor;  
        $item.UpdateOverwriteVersion(); 

        # Check in 
        $file.CheckIn("Updated by System");
    }
}
share|improve this question

1 Answer 1

up vote 2 down vote accepted

As suggested here: http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/1f42e45e-160f-457d-b4dd-cb228e49abb7

You should use following fields along with UpdateOverwriteVersion() method to update fields such as author, date created etc.

// The actual User Information is within this SPListItem 
                    SPListItem userItem = documentList.Items.GetItemById(1);                   
                    userItem["Created By"] = currentWeb.EnsureUser("user").ID; 
                    userItem["Modified By"] = userItem["Modified By"]; 
                    userItem["Created"] = DateTime.Now.AddYears(-3); 
                    userItem["Modified"] = DateTime.Parse("01/01/2000");
                    userItem.UpdateOverwriteVersion();
share|improve this answer
    
Thanx, I'll try this. –  Benny Skogberg MCSA Apr 23 '12 at 15:15
2  
It didn't work, the vti_author property stays the same. Sorry. –  Benny Skogberg MCSA Apr 23 '12 at 19:57

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.