Reading file content to string in .Net Compact Framework

lng picture lng · Jul 27, 2011 · Viewed 94.9k times · Source

I am developing an application for mobile devices with the .net compact framework 2.0. I am trying to load a file's content to a string object, but somehow I can't get it done. There is no ReadToEnd() method in the System.IO.StreamReader class. Is there another class that provides this functionality?

Answer

Jethro picture Jethro · Jul 27, 2011
StringBuilder sb = new StringBuilder();
using (StreamReader sr = new StreamReader("TestFile.txt")) 
{
    String line;
    // Read and display lines from the file until the end of 
    // the file is reached.
    while ((line = sr.ReadLine()) != null) 
    {
        sb.AppendLine(line);
    }
}
string allines = sb.ToString();