Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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!!

share|improve this question
    
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. –  Vedran Rasol 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. –  Vedran Rasol Sep 21 '11 at 22:29
    
Thanks Vedran. I will try out few other things! –  Emon Sep 22 '11 at 13:55
add comment

1 Answer

up vote 1 down vote accepted

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

uploadedFile.Item.SystemUpdate(false);

to:

uploadedFile.Item.UpdateOverwriteVersion();

And that did the trick!

share|improve this answer
    
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 –  Tim Gabrhel Sep 22 '11 at 17:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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