Instead, you need to traverse all versions of a document, which raises a critical issue. How to ensure the created, createdby, modified and modifiedby properties to be the same in the new document as in the old.
SPFileCollection contains an Add method to add new files. Unfortunately it doesn't exists with all the parameters needed, i.e. properties as well as created, createdby, modified and modifiedby. This method is missing:
SPFileCollection.Add (String, Byte[], Hashtable, Boolean, SPUser, SPUser, DateTime, DateTime)
As this method doesn't exists you have two options.
- Copy document with properties - and fix dates and users manually afterwards
- Copy document with dates and users - and fix properties manually afterwards
Both methods raises some issues - as you need to manipulate the SPFile and SPListItem object directly.
Manually manipulating createdby can be done as sketched below:
listitem["Created"] = new DateTime(2006, 11,1);
listitem["Modified"] = new DateTime(2006, 12,1);
listitem.UpdateOverwriteVersion();
as outlined on MSDN. Unfortunately this code doesn't work :-(
Other ideas very much appreciated.
Check out other blogs, such as this. Unfortunately it doesn't addess all the issues.
Hint to a solution?
Various investigations led me to analyzing the properties of the listitem after having added the item. It turns out that:
listitem[SPBuiltInFieldId.Created]
listitem[SPBuiltInFieldId.Created_x0020_Date]
are not equal! Created_x0020_Date contains the value of li["Created"] whereas SPBuiltInField.Created was the time the document was added to SharePoint.
This is even the case in situations where you use the
SPFileCollection.Add (String, Byte[], SPUser, SPUser, DateTime, DateTime)
which was a surpise to me !
4 comments:
Hi Morten
Perhaps the issue regarding the ID of the original creator of the entry could be handled as suggested by the accepted answer:
http://stackoverflow.com/questions/624549/add-elements-to-an-an-announcements-list-for-a-specific-user
What a great web log. I spend hours on the net reading blogs, about tons of various subjects. I have to first of all give praise to whoever created your theme and second of all to you for writing what i can only describe as an fabulous article. I honestly believe there is a skill to writing articles that only very few posses and honestly you got it. The combining of demonstrative and upper-class content is by all odds super rare with the astronomic amount of blogs on the cyberspace.
maybe this http://dandd.codeplex.com solution can do the trick
This does not inform how to copy libraries in sharepoint. How do you make a library a template?
Post a Comment