locked
Read a file with .Net Standard 2.0 RRS feed

  • Question

  • Hi there!

    I've updated my UWP app to SDK 16299. It says that .net standard 2.0 api is available. Yes, it is! But it doesn't work. At least in my case. 

    It worked well with UWP API and doesn't work with .Net standard 2.0

     
    // I get file with Browsing dialog and it worked well with UWP api
    StorageApplicationPermissions.FutureAccessList.Add(file);
    var bytes = System.IO.File.ReadAllBytes(file.Path);

    The question is very interesting for me. 

    Because I'm going to write a cross platform library for Xamarin.Forms and now it's seems that I'm stuck with PCL again.

    Thank you in advance.

    Tuesday, November 7, 2017 3:16 PM

Answers

  • I assume that the problem you have here is file permissions. Your app has direct permissions to read its install location and its application data. For other locations it needs to go through the file broker via the StorageItem classes (either directly or by getting a brokered Win32 file HANDLE from the StorageItem via IStorageHandleAccess and initialize a System.IO.File from that handle). I discussed this in more detail in my blog entry https://blogs.msdn.microsoft.com/wsdevsol/2012/12/04/skip-the-path-stick-to-the-storagefile/

    .Net Standard 2.0 is not relevant here. System.IO.File was available to UWP apps prior to .Net Standard 2.0, and .Net Standard 2.0 does not affect file permissions. 

    For help with Xamarin please post in the Xamarin forums at http://forums.xamarin.com . 


    Tuesday, November 7, 2017 5:30 PM