2

How can I detect the "Downloads" folder in Xamarin forms? And do I need specific rights? I cannot find a matching variable on this in GetFolderPath() nor FileSystemHelper. Thx

FreakyAli
  • 13,349
  • 3
  • 23
  • 63
Michael Wagner
  • 211
  • 4
  • 9

1 Answers1

4

In android, from external files, we can get Downloads folder by following code:

 string path1 = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, Android.OS.Environment.DirectoryDownloads);

The path like /storage/emulated/0/Download/

In ios, use this directory to store user documents and application data files.

var documents = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);

If you want to add or modify file in Download folder, you need request permissions in Android platform.

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

There is one thread that you can take a look:

How to open PDF file in xamarin forms

Cherry Bu - MSFT
  • 10,160
  • 1
  • 10
  • 16
  • 3
    Beware of the new Android 11 MANAGE_EXTERNAL_STORAGE permission that is needed. WRITE_EXTERNAL_STORAGE will be completely ignored with Android 11. (With Android 10 and android:requestLegacyExternalStorage="true" in manifest it would still work.) – thomiel Mar 14 '22 at 14:00
  • 1
    Note that Environment.ExternalStorageDirectory is deprecated in Api level 29. – Innova Dec 23 '22 at 12:20