5

We are using below line to get Last access date and time of the file.

DateTime dtLastAccesstime = File.GetLastAccessTime(sFilePath);

But we are facing strange problem, the above call itself modifies the Last access time. So effectively we are getting current time as last access time.

Marco
  • 56,740
  • 14
  • 129
  • 152
SantoshTupe
  • 61
  • 1
  • 4
  • Are you sure that there is no code near that line that may have modified the last access date? – madd0 Nov 29 '11 at 14:29
  • 5
    Are you doing anything with `sFilePath` before this line of code? There's a good article by Raymond Chen with a [non-exhaustive list of innocuous activities that update the last accessed time](http://blogs.msdn.com/b/oldnewthing/archive/2011/10/10/10222560.aspx) – Damien_The_Unbeliever Nov 29 '11 at 14:30

1 Answers1

7

You may find this post useful, in particular:

Starting in Windows Vista, maintaining the last-access time is disabled by default.

Which means that nowadays most operating systems won't maintain the last access time (which I suppose could account for the odd behaviour you are seeing).

Even if this is not the case this post highlights some of the many scenarios whereby the last access time could have been updated when you didn't mean to - can you be sure that your application doesn't perform any other file access?

Justin
  • 84,773
  • 49
  • 224
  • 367
  • Hi, thanks for your comments and help. We have explained our client about this and he has agreed to exempt LastAccessTime from requirements. – SantoshTupe Dec 01 '11 at 05:34