locked
getting the Datetime from windowexplorer RRS feed

  • Question

  • User351619809 posted

    Hi All,

    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
        End Function

    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.

    Tuesday, March 1, 2016 6:47 PM

Answers

  • User614698185 posted

    Hi anjaliagarwal5,

    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.

    System.IO.File.GetLastWriteTime(Server.MapPath("myFile.txt")).ToString("HH:mm:ss");

    Please see: http://www.csharp-examples.net/file-creation-modification-time/

    Best Regards,

    Candice Zhou

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 2, 2016 3:03 AM

All replies

  • User614698185 posted

    Hi anjaliagarwal5,

    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.

    System.IO.File.GetLastWriteTime(Server.MapPath("myFile.txt")).ToString("HH:mm:ss");

    Please see: http://www.csharp-examples.net/file-creation-modification-time/

    Best Regards,

    Candice Zhou

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 2, 2016 3:03 AM
  • User351619809 posted

    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.

    Wednesday, March 2, 2016 5:03 AM