2014-10-05 54 views
0

預定義數據庫(.db)應該添加以及如何在Windows Phone 8.1應用程序中使用它? 我沒有在我的應用程序中使用Silverlight。 我試圖做這樣的事情Windows Phone 8.1應用程序中預定義的數據庫

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)中做同樣的事情。

回答

0

當我看到你試圖將數據庫從複製到IsolatedStorage和你的目標WinRT的。示例代碼可以llok這樣的:

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.

相關問題