Xamarin Forms Open/Save File to Documents

Sunshine Coast 116 Reputation points
2020-11-24T10:54:48.127+00:00

I've read in some posts that Xamarin Forms won't allow access to the common external folders such as Documents/Pictures/etc... But when using the 'CrossFilePicker' addin it seems to allow access to files outside of the local App shell space. I assume any other file picker for Xamarin Forms will do the same.

My question is ...
How come these file pickers can access common file directory files outside the App space. but we cannot do the same through code ?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,294 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 68,571 Reputation points Microsoft Vendor
    2020-11-24T12:18:59.713+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    Xamarin Forms won't allow access to the common external folders such as Documents/Pictures/etc... But when using the 'CrossFilePicker' addin it seems to allow access to files outside of the local App shell space.

    It is not xamarin forms do not allow access to the common external folders, Platform do not allow access to the common external folders.

    For example, starting in Android 11, apps that use the scoped storage model can access only their own app-specific cache files. apps cannot access the public file path.

    How come these file pickers can access common file directory files outside the App space. but we cannot do the same through code ?

    If you use Android 11, it cannot be achieved. If you use Android 10 or before, you can add android:requestLegacyExternalStorage in the application tag.

       <manifest ... >  
         <!-- This attribute is "false" by default on apps targeting  
           Android 10 or higher. -->  
         <application android:requestLegacyExternalStorage="true" ... >  
          ...  
        </application>  
       </manifest>  
    

    https://developer.android.com/about/versions/11/privacy/storage#manage-device-storage

    Best Regards,

    Leon Lu


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Laszlo Alt 11 Reputation points
    2020-12-06T20:44:41.98+00:00

    @Leon Lu (Shanghai Wicresoft Co,.Ltd.) This is what most people are suggesting but I haven't been able to find any examples on Xamarin other than Android Java documentation on this.

    0 comments No comments