I am trying to migrate some document into SharePoint 2010 doc library and would like to retain the "modified" and "modified by" value of the document. I am able to store the document into a doc lib and set the "modified by" value but cannot store the "modified" date properly. Following is my code:
var list = web.Lists[new Guid("751e4d84-44a8-4d58-8151-2f14fca70645")];
var folderItem = list.RootFolder.SubFolders.Cast<SPFolder>().FirstOrDefault(f => f.Name == "Tax");
foreach (File x in files) {
var author = context.Web.EnsureUser(x.LastModifiedBy);
var lastModified = x.LastModified;
SPFile uploadedFile = folderItem.Files.Add(x.FileName, x.Content, author, author, lastModified,
lastModified);
uploadedFile.Item["Created"] = lastModified;
uploadedFile.Item["Modified"] = lastModified;
uploadedFile.Item.SystemUpdate(false);
}
As you can see I have 4 files in the files collection. For some weird reason, the first file is not retaining the modified date I am setting. The last 3 files store the date just fine. Is there something I am missing?
Thanks!!
lastModifiedto some different DateTime value (eg. Now) - just to check if all files are updated as expected? Maybe is problem in first file Modified date field but I am not sure what could be wrong with it. – Vedran Rasol Sep 21 '11 at 22:19