2014-05-13 105 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

相关问题