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,
                uploadedFile.Item["Created"] = lastModified;
                uploadedFile.Item["Modified"] = lastModified;

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?


  • As far as I can see nothing is wrong here. Did you tried to set lastModified to 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. Sep 21 '11 at 22:19
  • And try code example provided at SPFileCollection.Add Method without using LINQ. I really don't have a clue what is wrong. I am just trying to give you some troubleshooting ideas. I hope you don't mind. Sep 21 '11 at 22:29

Figured out the issue... I have changed the code from:




And that did the trick!

  • Take a look here msdn.microsoft.com/en-us/library/ms481195.aspx When passing false into the SystemUpdate method, you are saying do NOT update the current version, timestamp, etc. If you set it to true, you will have a new version and modified date. However, your solution will retain the current version (if necessary) but update the timestamp Sep 22 '11 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.