Updating the Created Date of a Document or List Item Programmatically
Posted by mundeep on May 22, 2009
A common tasks developers are required to do with Sharepoint is migrated documents from either legacy systems or older Sharepoint sites into a document library. There are many ways to do this documented out there (most commonly using the Files.Add method of the API), but one of the common requirements during this ‘migration’ is to retain the Created Date or Created By fields. Sowmyan’s blog has a good description of how to set the Created By/Modified By user fields here.
Updating the Created Date of a document or list item in Sharepoint is even easier, simply set the “Created” field of the item to the value you wish to set. For example if using the Files.Add methods in the API (as described by Dave Hunter) then the following code snippet will update the Created Date:
// add the file SPFile file = docLib.RootFolder.Files.Add(newFileName, inputStream); // get the list item for that file SPItem item = file.Item; //Set the Created Date item["Created"] = "2009-02-26 15:00:00"; item.Update();