How to get the correct LastModifiedDate from SPFile in SP2013

3.1k views Asked by At

I've got a Issue with SharePoint 2013 Files in Libraries. If I push an File via WebDAV into an Folder the file will still hold it's created/modified date (and that's good!). Other Case is: I use the "New Document" Upload Form - the File will be newly created and loses its correct created/modified date.

I'm looking for a way to get these correct Values of the SPFile Item.

DateTime modified = Li.File.TimeLastModified;

That's my current attempt to get the DateTime but it only retrieves the "sharepoint" value and not the "filesystem" value of the LastModifiedDate.

I tried to let my Webpart open the File on the server.. but URI-Formats arent supported :-(

Has anybody already run into this problem?

Thanks for your help in advance!

EDIT:

This is what I get in explorer view of the document library. For example the file lync.PNG has a last modified date of 26.12.2013.

webdav

this is what I get from my webpart using the code snippet (sorry for the german description; "geƤndert am" means lastmodifieddate)

library

1

There are 1 answers

1
Eric Gregorich On

You can get the modified date that SharePoint uses by getting the Item of the SPFile then reading the date property. Something like this:

DateTime date = DateTime.Parse(file.Item["Modified"].ToString());

Once its in SharePoint any changes should come from the modified property of the item. You would have to use an event receiver to capture the original file date and then overwrite the SharePoint created date, or add the value to another field in the item.

Hope this helps.