Sunday, March 30, 2008

Change approval status without changing ModifiedBy property on a document

We have created a copy-paste utility for SharePoint 2007 which enables documents to be moved from one place within SharePoint to another.

When we move or copy the file we include properties as well as versions with Createdy, ModifiedBy, TimeCreated and TimeLastModified. Everything works fine except for one issue.

When we publish a document using SPFile.Publish() the ModifiedBy and TimeLastModified are changed - therefore we lose the version history.

Instead we try to fix the issue using the comment field - somehow it solves part of the issue but we would appreciate a better solution.

We have tried changing



oFile.Item.ModerationInformation.Status = SPModerationInformation.Approved

oFile.Item.ModerationInformation.Comment = [comment]


but unfortunately ModerationInformation is not available on the SPFile object.

This blog mention the same issue - without a solution. Ideas appreciated.

As our last resort we're currently investigating creating a stored procedure which modified the SharePoint SQL database behind the scene. We would prefer not using this solution (albeit it works).


Bjørn Furuknap said...

Have you looked into using the content migration API? I don't know your exact problem statement so I wont be able to say if this will work for you, but you do have a vast number of options to tailor your import and export.

I recommend 'Stefan Goßner : Deep Dive into the SharePoint Content Deployment ' for getting the basics down, and you friendly copy of MSDN for the gritty details.

Good luck, and feel free to let me know if it works for you :-)

Sravan Kasyap K said...

Morten, Did you find a solution to this problem that you stated? I am also experiencing the same problem. When i use Publish() method it publishes document but the modified by is changed to "System Account" and modified field is also updated to current date as you mentioned in the blog.

Hope to see some response from you. My Email id is

Thanks in advance.
Sravan Kasyap K.

Star said...


Did anyone get a solution to this - i am also trying to retain the createdBy and modifiedBy users after publish() but it get reverted to the system account - is there a way around this?

Help would be greatly appreciated!



Star said...


Did anyone get a solution to this? I am also trying to retain the createdBy and modifiedBy users after publish() but these are beign reverted to the system account. Can someone help on how I get around this?

Help would be much appreciated!



Navish Rampal said...

The properties wont be maintained after Publishing.

Solution to this is insted of publishing. Call the approve method on SpFile Object. i.e destFile.Approve()

And after that.
SPListItem item = destFile.Item;
item["Created"] = Give the Date;
item["Modified"] = Specify the Date; item.SystemUpdate(false);

Anonymous said...

var modified = file.Item["Modified"];
var editor = file.Item["Editor"];


file.Item["Modified"] = modified;
file.Item["Editor"] = editor;