question

SunshineCoast-8527 avatar image
0 Votes"
SunshineCoast-8527 asked LaszloAlt-7758 published

Xamarin Forms Open/Save File to Documents

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 ?

dotnet-xamarinformsdotnet-xamarinessentials
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LeonLu-MSFT avatar image
1 Vote"
LeonLu-MSFT answered

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.




5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LaszloAlt-7758 avatar image
0 Votes"
LaszloAlt-7758 answered LaszloAlt-7758 published

@LeonLu-MSFT 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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.