【发布时间】:2015-02-15 19:40:04
【问题描述】:
我正在尝试用图片目录中的数据库覆盖本地文件夹中的数据库,我使用以下内容
StorageFolder storageFolder = KnownFolders.PicturesLibrary;
String picName = "SqlLiteWin8-1.db";
var file2 = await storageFolder.TryGetItemAsync(picName) as IStorageFile;
StorageFile fileCopy = await file2.CopyAsync(Windows.Storage.ApplicationData.Current.LocalFolder, "SqlLiteWin8-1.db", Windows.Storage.NameCollisionOption.ReplaceExisting);
它似乎工作,文件被复制并覆盖旧文件 问题是当我运行应用程序时它仍然显示旧数据
我通过手动删除应用程序本地状态文件夹中的数据库然后运行代码并将其复制到文件夹中进行检查。 我认为它仍在使用应用程序包中的数据库,而不是本地文件夹中的数据库
图片目录中的数据库与应用程序中存储的数据库相同,只是修改了1条记录
我想覆盖它,这样我就可以向用户提供一个新的数据库文件,并且应用程序将使用新数据,或者有没有办法绕过这个并直接从图片目录而不是本地文件夹读取数据库
其中之一是它使用以下代码检查数据库是否存在,如果不存在则复制,这可能是导致它无法工作的原因
public static async Task<bool> checkDataBaseConnection()
{
bool isDatabaseExisting = false;
try
{
var uri = new Uri("ms-appx:///SqlLiteWin8-1.db"); //in application folder
var file = await StorageFile.GetFileFromApplicationUriAsync(uri);
var destinationFolder = ApplicationData.Current.LocalFolder;//local appdata dir
//await file.DeleteAsync();
// var f = await destinationFolder.GetFileAsync("data.db3");
await file.CopyAsync(destinationFolder);
}
catch (Exception ex)
{
throw ex;
isDatabaseExisting = false;
}
if (!isDatabaseExisting)
{
StorageFile databaseFile = await Package.Current.InstalledLocation.GetFileAsync("AFSMOJO.db");
await databaseFile.CopyAsync(ApplicationData.Current.LocalFolder);
}
return isDatabaseExisting;
}
非常感谢您的帮助
标记
【问题讨论】:
标签: c# windows-store-apps copy local-storage