Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access public download folder in every platform in Xamarin.Forms

I need to create a backup service so I intend to save the SQLite database file on each platform. The saved file should be available after the uninstall of the app.

I intend to use the Downloads folder (which should be available on every platform).

I have created an interface and use the following code per platform:

Interface:

public interface IBackupService
{
  string GetDownloadPath();
}

Android:

public string GetDownloadPath()
{
  return Android.OS.Environment.DirectoryDownloads;
}

UWP:

public string GetDownloadPath()
{
  return Windows.Storage.KnownFolders.???????;
}

What should I do about that? Is there a public library that I could use?

like image 690
Nestor Avatar asked Dec 07 '25 06:12

Nestor


1 Answers

There does not seem to be a general downloads folder as per this documentation on KnownFolders. So your assumption on the Downloads folder being on every platform doesn't seem to be correct.

If we dive in a bit further we get to the DocumentsLibrary which seems the obvious choice for this kind of purpose, but it is not. Microsoft says:

The Documents library is not intended for general use. For more info, see App capability declarations. Also, see the following blog post. Dealing with Documents: How (not) to use the documentsLibrary capability in Windows Store apps

The paragraph after that seems to describe what we have to do then;

If your app has to create and update files that only your app uses, consider using the app's local folder. Get the app's local folder from the Windows.Storage.ApplicationData.Current.LocalFolder property.

So, as I can extract from your question you only want to use storage for your app, so the Windows.Storage.ApplicationData.Current.LocalFolder seems to be the right choice according to Microsoft.

like image 102
Gerald Versluis Avatar answered Dec 12 '25 03:12

Gerald Versluis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!