Nestor
Nestor

Reputation: 8404

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?

Upvotes: 4

Views: 7758

Answers (1)

Gerald Versluis
Gerald Versluis

Reputation: 34128

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.

Upvotes: 1

Related Questions