Hi,
I've an app in xamarin.form where I use a sqllite database to store data.
I have an interface where there is a method in order to get the path of the file.
For the android part this method is implemented in this way:
public string GetLocalFilePath(string filename)
{
string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
return Path.Combine(path, filename);
}
and when I open the connection to the database I use this code:
conn = new SQLiteConnection(DependencyService.Get().GetLocalFilePath("mydb.db"));
Furthermore I have another method to copy the database from this location to another in order to perform some backups.
public void BackupDatabaseToPersonalFolder(string sourceFilename, bool overwrite)
{
var sourcePath = GetLocalFilePath(sourceFilename);
string destinationFilename = string.Format("mydb_{0:dd-MM-yyyy_HH-mm-ss-tt}.db", System.DateTime.Now);
string path = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads).AbsolutePath;
string dbPath = Path.Combine(path, destinationFilename);
System.IO.File.Copy(sourcePath, dbPath, overwrite);
}
The problem is when I call this method the database saved in the download folder is empty with no tables in it but actually I've tables with the data inside.
DependencyService.Get().BackupDatabaseToDownloadFolder(DependencyService.Get().GetLocalFilePath("mydb.db"), true);
What's the problem?
What I'doing of wrong?
Thanks in advanced.
Daniele