Reputation: 6947
I have a basic c# UWP app running on Windows 10.
I'm trying to get the last access time for a StorageFile
like this:
var basicProperties = await file.GetBasicPropertiesAsync();
var moreProperties = await basicProperties.RetrievePropertiesAsync(
new string[] { "System.DateAccessed" });
var dateAccessed = moreProperties["System.DateAccessed"];
However, the date I get is wrong. It is too far in the past.
If I take a look the Properties in the Windows explorer or on the command line, the date is correct and updates each time I open the file in my app.
Get-ChildItem '.\test.txt' | select -ExpandProperty lastacc
Only in my app, the last access time is wrong. Am I trying to access the wrong property or is there another way to get the last access time?
UPDATE:
It turns out that File.GetLastAccessTime(file.Path);
does return the correct time as it is reported on the command line. I went for the StorageFile route, because the app is sandboxed and did not try the path based API before.
All of the above assumes that the file system is set up to keep track of the last access date in the first place.
Upvotes: 0
Views: 199