Change the build action from Resource
to Content
.
How to use an existing sqlite database on windows phone 8 with cordova
-
16-06-2023 - |
Pergunta
I'm building an hybrid app with cordova 3.0. I use a plugin to store my data in a sqlite database. On android and ios I have some scripts, which copy the database to the apps "documents" folder, where I can read/write to that pre filled database. Now I want to archive the same on windows phone 8.
I found a tutorial on: http://wp.qmatteoq.com/import-an-already-existing-sqlite-database-in-a-windows-8-application/
But it's not cordova related.
This is what my code looks like:
namespace com.example.hello
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
this.CordovaView.Loaded += CordovaView_Loaded;
}
private async void CordovaView_Loaded(object sender, RoutedEventArgs e)
{
await CopyDatabase();
this.CordovaView.Loaded -= CordovaView_Loaded;
}
private async Task CopyDatabase()
{
bool isDatabaseExisting = false;
try
{
StorageFile storageFile = await ApplicationData.Current.LocalFolder.GetFileAsync("my.db");
isDatabaseExisting = true;
}
catch
{
isDatabaseExisting = false;
}
if (!isDatabaseExisting)
{
StorageFile databaseFile = await Package.Current.InstalledLocation.GetFileAsync("my.db");
await databaseFile.CopyAsync(ApplicationData.Current.LocalFolder);
}
}
}
}
But I always get an exception "System.IO.FileNotFoundException". But the .db file is still at the right place. If I use a snippet to display all files in "ApplicationData.Current.LocalFolder", my sqlite fill is still there.
I also have a gist with an screenshot https://gist.github.com/pille72/9615840
Solução