Search code examples
c#getfilesfileversioninfo

how to get file last modified date?


I have one mistake .Why I dont know I want to take this file last modified date .but I have problem enter image description here

in my code : date is coming always 01011601 why?Do you have any suggestions ?

enter image description here

File properties : enter image description here


Solution

  • If the path you're getting your files from (pthh) is not the directory your app is running in, I would expect this date.
    When you're calling File.GetLastWriteTime(sqzfiles[i]) you are now relying on only the file name, so relative pathing is being used. Most likely, that file is not in your app's directory (although it is in pthh).

    Since the file at the relative path does not exist, the documentation will explain your unexpected date:

    If the file described in the path parameter does not exist, this method returns 12:00 midnight, January 1, 1601 A.D. (C.E.) Coordinated Universal Time (UTC), adjusted to local time.

    I've also seen this happen if the file is locked by another application, for what it's worth.