windows 8 - How write a .txt file in c# using StreamReader in Metro App? -


i'm having trouble creating streamreader object in windows 8 metro application. i'm trying make read text file in local directory keep showing me error. has solutions or other alternative solutions?

i'm using ms visual studio ultimate 2012, metro application.

code:

        int level = 1;          var filename = string.format(@"mazes\level{0}.txt", level);          using (var sr = new streamreader(filename))         {             var l = 0;             while (!sr.endofstream)             {                 string line = sr.readline();                  (var c = 0; c < line.length; c++)                 {                     mazevalues[c, l] = line[c];                      if (mazevalues[c, l] == '1')                     {                         var glass = new glass();                         glass.setvalue(grid.columnproperty, c);                         glass.setvalue(grid.rowproperty, l);                         grdmaze.children.add(glass);                         mazeglasses[c, l] = glass;                     }                 }                 l++;             }         } 

error showing:

the best overloaded method 'system.io.streamreader.streamreader(system.io.stream)' has invalid arguements.

windows.storage.storagefile.getfilefromapplicationuriasync , windows.storage.fileio.readlinesasync can used this.

using system; using windows.storage; async void test2() {      var filename = string.format(@"ms-appx:///mazes/level{0}.txt", level);     try      {         var file = await storagefile.getfilefromapplicationuriasync(new uri( "ms-appx:///assets/textfile1.txt"));         var lines = await fileio.readlinesasync(file);         foreach (var line in lines)         {             // code process each line here         }     }     catch (exception e)     {          // handle exceptions     } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -