The Jimzland

                           The land of language research…

RSS
和谐,创造更美好的世界!

Throwing Away Your “‘System.IO.File’ does not contain a definition for ‘ReadAllLines’” Error Message!

Note: You can also read this post on http://students.netindonesia.net/blogs/mrjimoy_05/archive/2011/08/18/throwing-away-your-quot-system-io-file-does-not-contain-a-definition-for-readalllines-quot-error-message.aspx

It’s a simple post but hope it’s helpful for you who need it. Recently I am in doing my project (using Microsoft Visual Studio 2010) and it was annoying! I can’t throw away these message after trying a lot of fixing. Take a look on the code below:

      if (File.Exists(_file))
      {
        string[] linesArray = File.ReadAllLines(yourFile);
        _lines = linesArray.ToList();
      }

For some computer, maybe the error doesn’t appear and the solution running slightly without any constraint. But if you get an error message sounds: ‘System.IO.File’ does not contain a definition for ‘ReadAllLines’, look at the figure below:

Then try to change your code become:

      if (File.Exists(yourFile))
      {
        using (StreamReader sr = new StreamReader(yourFile))
        {
          string line;
          while ((line = sr.ReadLine()) != null)
            _lines.Add(line);
        }
      }

It will fixed your problem :)

Notes: If you have anything to say about the article, please leave a comment. Please show a detail explanation (just like if you’ve got any error, attach the error message) so it should be easier for me to help you.
(attach the file if needed (Only: jpg, jpeg, png, gif, zip files can be uploaded)).

If you enjoy this post, please share it to your friends! :)
  • Facebook
  • Twitter
  • Google Bookmarks
  • Digg
  • del.icio.us
  • Live
  • LinkedIn
  • Add to favorites
  • Print
  • PDF

Comments are closed.