Last post Mar 02, 2016 05:03 AM by email@example.com
Mar 01, 2016 06:47 PMfirstname.lastname@example.org|LINK
I am trying to get the Datetime from window explorer in my .net code. I tried to do it like this, but did not get the correct date time.
Dim test As DateTime = GetExplorerDateTime(tempFile)
Private Function GetExplorerDateTime(Filename As FileInfo) As DateTime
Dim now As DateTime = DateTime.Now
Dim localOffSet As TimeSpan = now - now.ToUniversalTime()
Return File.GetLastAccessTimeUtc(filename.Name) + localOffSet
My file in window explorer looks like this:
Name Date modified Type Size
TestFile 4/16/2015 08:08 PM Text Document 3 KB
I am trying to get 4/16/2015 08:08 PM. I tried to Google it, but none of the code seems to be getting the correct date time from the window explorer.
Any help will be greatly appreciated.
Mar 02, 2016 03:03 AM|Candice Zhou|LINK
If you want to get file last modified time, you could use the LastWriteTime or the LastWriteTimeUtc property to get or set the last time the file was modified.
Mar 02, 2016 05:03 AMemail@example.com|LINK
I did try LastWriteTime and LastWriteTimeUTC, but both of them are returning the current date and time so I ran the code today, it kept giving me 3/1/2016.
I tried FileInfo.LastWriteTime. I am not sure if I am doing something wrong here, but couldn't get the file last modified time.