Thanhtu150
Thanhtu150

Reputation: 91

Cannot access LastAccessTime of file in UWP app

Please see this image below: enter image description here

How can i get value such as: LastAccesstime, LastWritetime, Length..v.v.. from Fileinfo fi ?

Upvotes: 0

Views: 180

Answers (1)

Romasz
Romasz

Reputation: 29792

In UWP the most suitable way to access files is through StorageFiles rather than directly by path. In this case you may take a look at StorageFile.GetBasicPropertiesAsync() method:

foreach (StorageFile contentStream in pickedFile)
{
    var prop = await contentStream.GetBasicPropertiesAsync();
    DateTimeOffset lastModification = prop.DateModified;
    DateTimeOffset itemTime = prop.ItemDate;
    ulong size = prop.Size;
    //...
}

The problem with FileInfo is that in most cases you don't have privilege to access file via its path, whereas StorageFile works like a broker and file open picker grants privilege.

Upvotes: 1

Related Questions