【发布时间】:2014-03-18 15:07:40
【问题描述】:
我正在使用cordova 3.0 构建一个混合应用程序。我使用插件将我的数据存储在 sqlite 数据库中。在 android 和 ios 上,我有一些脚本,它们将数据库复制到应用程序的“文档”文件夹中,我可以在其中读取/写入该预填充的数据库。现在我想在 windows phone 8 上存档。
我找到了一个教程: http://wp.qmatteoq.com/import-an-already-existing-sqlite-database-in-a-windows-8-application/
但这与科尔多瓦无关。
这是我的代码的样子:
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);
}
}
}
}
但我总是得到一个异常“System.IO.FileNotFoundException”。但是 .db 文件仍然在正确的位置。如果我使用 sn-p 显示“ApplicationData.Current.LocalFolder”中的所有文件,我的 sqlite 填充仍然存在。
【问题讨论】:
-
这可能与文件权限有关吗?查看System.Io.FileNotFound Win7
-
您找到解决方案了吗?我也面临同样的问题
标签: c# sqlite cordova windows-phone-8 cordova-3