【发布时间】:2016-04-17 19:31:06
【问题描述】:
我的 Windows 应用商店应用未能通过认证,因为我正在编写 InstalledLocation 文件夹而不是本地文件夹。
如果现有的 SQLite 数据库不存在,我会将其加载到应用程序中。
下面是我的代码:
private static string dbName = "flashcards2015a.db";
private static string dbPath = string.Empty;
public MainPage()
{
this.InitializeComponent();
LoadDataTask();
LoadDecksNames();
}
private async void LoadDataTask()
{
await CreateIfNotExists(dbName);
}
private async Task CreateIfNotExists(string dbName)
{
if (await GetIfFileExistsAsync(dbName) == null)
{
StorageFile seedFile = await StorageFile.GetFileFromPathAsync(Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, dbName));
await seedFile.CopyAsync(Windows.Storage.ApplicationData.Current.LocalFolder);
}
}
如何将代码更改为本地文件夹以获取 db 文件?
【问题讨论】:
-
你确定是这个问题吗?您显示的代码不会写入安装位置。它似乎正确地将种子数据库从安装位置复制到本地存储。出错的地方是它没有等待 LoadDataTask,因此 LoadDecksNames 可能在 LoadDataTask 复制文件之前被调用。在不知道 LoadDecksNames 的情况下,我不知道它是回到种子还是遇到其他问题。
标签: c# windows-store-apps uwp