2014-01-08 50 views
10

我試圖從我的Assets文件夾中讀取json文件。我已經嘗試了很多代碼示例,並且都是同一件事情上的變體。FileNotFoundException從Windows應用商店中的Assets文件夾中讀取JSON文件

我覺得我一定在做一些愚蠢的事情,但我看不到它。

string filepath = @"Assets\resources.json"; 
StorageFolder folder = Windows.ApplicationModel.Package.Current.InstalledLocation; 
StorageFile file = await folder.GetFileAsync(filepath); // error here 
var data = await Windows.Storage.FileIO.ReadTextAsync(file); 

每當我運行上面的代碼,我的應用程序上就會得到System.IO.FileNotFoundException。我檢查了兩倍和三倍的文件在資產文件夾中,並且在我的路徑中沒有錯別字。

我也試過這個

StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/resources.json")); 

同樣的錯誤。 System.IO.FileNotFoundException

我的資產文件夾的截圖:

Screenshot of my Assets folder

回答

24

在這個被選定爲內容生成操作你確信該文件(右鍵和屬性)的屬性?還要確保複製到輸出目錄設置爲複製總是。這應該解決你的問題,我認爲。

+0

謝謝,就是這樣! – roryok

+0

謝謝你的伴侶 – AbsoluteSith

+0

謝謝這幫了我.. :) –

相關問題