【问题标题】:Writing to the InstalledLocation folder写入 InstalledLocation 文件夹
【发布时间】: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


【解决方案1】:

您需要将 StorageFile.GetFileFromPathAsync 中的 Path.CombinWindows.ApplicationModel.Package.Current.InstalledLocation.Path 更改为 Windows.Storage.ApplicationData.Current.LocalFolder

更多信息:https://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.applicationdata.localfolder

【讨论】:

    【解决方案2】:

    您需要使用 StorageFile.GetFileFromApplicationUriAsync()。

    更多信息:https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh965322(v=win.10)

    var uri = new System.Uri("ms-appx:///images/logo.png");
    var file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(uri);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-07
      • 2011-08-21
      • 1970-01-01
      • 1970-01-01
      • 2021-12-22
      • 2013-02-19
      • 2013-12-06
      • 1970-01-01
      相关资源
      最近更新 更多