Search code examples
c#uwpwindows-10-universalfileinfo

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 ?


Solution

  • 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.