预定义数据库(.db)应该添加到哪里,如何在windows phone 8.1应用中使用?我没有在我的应用中使用Silverlight。我正试着做这样的事情
public MainPage()
{
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Required;
CopyDatabase();
}
private void CopyDatabase()
{
IsolatedStorageFile ISF = IsolatedStorageFile.GetUserStoreForApplication();
String DBFile = "myDB.sqlite";
if (!ISF.FileExists(DBFile)) CopyFromContentToStorage(ISF, "Assets/myDB.sqlite", DBFile);
}它显示无法找到名称空间名称IsolatedStorageFile。我在Windows-phone-8.0的一个示例数据库应用程序中找到了这些代码,我也试图在Windows-phone-8.1 (没有Silverlight)中做同样的事情。
发布于 2014-10-07 19:43:07
正如我所看到的,您试图将数据库从package复制到IsolatedStorage,并且您的目标是WinRT。示例代码可能如下所示:
private async Task<bool> CopyDatabase()
{
StorageFolder packageFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
StorageFile file = await packageFolder.GetFileAsync("Assets/myDB.sqlite");
await file.CopyAsync(localFolder);
return true;
}我已经从我的头顶写了这段代码,但我应该工作或帮助您找到解决方案。以上内容也可以通过Uri方案实现:
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(@"ms-appx:///Assets/myDB.sqlite"));有关Data and Files you will find at MSDN.的更多信息
https://stackoverflow.com/questions/26202856
复制相似问题