The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
help with reading from txt file RRS feed

  • General discussion

  • hello to all...
    i'm trying to do the next thing.
    i want to add a text file to my app project
    and read the data from it.
    all the examples i found give me an error.
    so can anyone tell me how to read from text file in my app.

    thank you for the help...

    Monday, January 9, 2012 12:24 PM

All replies

  • 1) add file in question to the project
    2) set the file to be of type Content and build action to be Always Copy

    using something like this

    var resource = System.Windows.Application.GetResourceStream(new Uri("textfile.txt", UriKind.Relative));  
    string line  
    using(StreamReader streamReader = new StreamReader(resource.Stream))  
    {  
       while((line = streamReader.ReadLine()) != null)  
       {  
           // do whatever you want with the line  
       }  
    }  
    Monday, January 9, 2012 12:33 PM
  • thank you for the help...
    now if i want to write to the file 
    what i need to do?

    thank for the help...
    Sunday, January 15, 2012 1:17 PM