【问题标题】:Predefined database in windows phone 8.1 appwindows phone 8.1 应用程序中的预定义数据库
【发布时间】:2014-10-07 19:51:59
【问题描述】:

预定义数据库 (.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)中做同样的事情。

【问题讨论】:

    标签: sqlite visual-studio-2013 windows-phone-8.1


    【解决方案1】:

    正如我所见,您尝试将数据库从 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.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-07
      • 1970-01-01
      • 2016-03-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多