SharePoint 2010: Set Author (CreatedBy) and Editor (ModifiedBy) in SPFile

Posted by user1508154 on Stack Overflow See other posts from Stack Overflow or by user1508154
Published on 2012-07-07T03:12:36Z Indexed on 2012/07/07 3:15 UTC
Read the original article Hit count: 614

Filed under:
|
|

I am writing a job to migrate documents to SharePoint 2010 and need to set Author and Editor to the original user for the Source System.

The way I have done it was

dim ImportFile as SPFile
dim ImportFolder as SPFolder
dim InternalOperatorUser as SPUser
...
ImportFile = ImportFolder.Files.Add(ImportFileName, contents, CreatedBy, ModifiedBy, TimeCreated, TimeModified)
...
ImportFile.Item("Author") = InternalOperatorUser 
ImportFile.Item("Editor") = InternalOperatorUser
ImportFile.Item.UpdateOverwriteVersion()
ImportFile.Item.SystemUpdate(False)
...

That is working fine and it is setting Author and Editor on the ListItem level correctly

  • SPFile.Item("Author")
  • SPFile.Item("Editor")

BUT (!!!) SharePoint also stores the Editor on the Attachment level which some tools use as display value instead. This value is set to the system user who is running that script

  • SPFile.Versions.Item(1).CreatedBy

This field is readonly. Is there a way to modifiy it so I can set InternalOperatorUser to be the Creator for the Attachment as well.

SharePoint 2010 Web only uses the values on the ListItem Attribites which are fine but there are thrid party tools that use the ones on the Attahcment level. Using SharePoint Explorer I could confirm that CreatedBy is set to be the system user.

Does anyone here know how to change this value as well?

Thanks, Wolfgang

© Stack Overflow or respective owner

Related posts about sharepoint2010

Related posts about editor