winapiuwpmsvcrtcrt

UWP: Permissions to use _stat()


I use the _stat function under UWP. But it repeatedly returns -1 for the absolute path to the file from my Images Library (C:\\Users\\<<my-user>>\\Pictures\\image_sample.png). I tried adding a permission to Images Library by adding to the manifest file the following:

  <Capabilities>
      <uap:Capability Name="picturesLibrary"/>
  </Capabilities>

But it didn't help in my case. Different Windows' API function work well (like I can read this file using for example StorageFolder::GetFolderFromPathAsync). But the _stat returns -1.

_stat works on UWP well when I use the relative path for files inside the app sandbox. Is it possible to use it for an external directory (for example to pictures library)?


Solution

  • Use Capability broadFileSystemAccess, and enable the File System permission in the app settings.

    You can search for your app in the Start Menu, click App settings, and open t File System in App permission. Another way, open Settings, Settings-> Privacy &security -> File System, find your app in the list and enable file permissions. (Win+R ms-settings:privacy-broadfilesystemaccess)

    I test UWP C++/WinRT project, follow the above steps to open file permissions, _stat works well, it returns 0 and can use absolute path.