2014-05-13 42 views
0

我最近一直試圖將名爲KS1words.txt的外部文本文件加載到Visual Studio 2012窗口存儲空白頁的列表視圖中,一旦使用列表視圖進入頁面。該代碼工作1天前,但與加載文件,我無法修復的錯誤,所以我創建了同樣的事情,一個新的方案,並制定了相同的代碼,現在不會,我已經在這裏和那裏連接它也是ListViews頁面的屏幕截圖。你有什麼想法問題的原因是什麼? 我在虛擬機上運行此! 謝謝將外部文本文件加載到Visual Studio 2012的ListView中(Windows存儲)

Screenshot

CODE:

private void Page_Loaded(object sender, RoutedEventArgs e) 
    { 
     FillList(@"Assets\KS1words.txt"); 
    } 
    async private void FillList(string filename) 
    { 
     var KS1wordlist= new List<String>(); 
     // this method reads line separated words from a text file and populates a List object // 
     Windows.Storage.StorageFolder localFolder = Windows.ApplicationModel.Package.Current.InstalledLocation; 
     // begin the file read operation 
     try 
     { 
      // open and read in the word list into an object called words 

      StorageFile sampleFile = await localFolder.GetFileAsync(filename); 
      var KS1wordsvar= await FileIO.ReadLinesAsync(sampleFile); 
      // add each word returned to a list of words declared 
      // globally as List wordList = new List(); 
      foreach (var word in KS1wordsvar) { KS1wordlist.Add(word); } 
      List1.ItemsSource = KS1wordlist; 
     } 
     catch (Exception) { 
      // handle any errors with reading the file 
     } 
+0

請具體談談什麼是「不工作」。你是否收到錯誤信息?如果該文件是在「資產」,那麼你必須確保該文件(在屬性選項卡)設置爲「複製到輸出」。這將確保文件將被複制到輸出目錄。 –

+0

對不起,我的意思是,該程序運行成功,沒有錯誤,但最終,它不顯示任何東西在listview..and是文本文件不在項目中,但我將它們添加到確切的頁面我試圖執行它們,結果仍然相同 – Atanas

+0

而且,是的,它被設置爲始終複製到輸出 – Atanas

回答

0

,因爲你正在使用

Windows.Storage.StorageFolder localFolder = Windows.ApplicationModel.Package.Current.InstalledLocation; 

得到的文件夾,請確保您的文本文件是在正確的目錄。

+0

是的,我的文件位於相同的文件夾中,其中編程文件是 – Atanas

相關問題