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.Publish([comment])
to
oFile.Item.ModerationInformation.Status = SPModerationInformation.Approved
oFile.Item.ModerationInformation.Comment = [comment]
oFile.Item.SystemUpdate(false)
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).
6 comments:
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 :-)
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 sravankasyapk@gmail.com.
Thanks in advance.
Sravan Kasyap K.
Hi,
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!
Thanks,
Saima
Hi,
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!
Thanks,
Saima
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);
var modified = file.Item["Modified"];
var editor = file.Item["Editor"];
file.Publish([comment]);
file.Item["Modified"] = modified;
file.Item["Editor"] = editor;
file.Item.SystemUpdate(false);
Post a Comment