0

I want to assign the contents of a text file to a textbox, like so:

String logDirPath = 
    Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
String fullPath = logDirPath + "\\application.log";
textBoxErrLogsContents.Text = File.ReadAllText(fullPath);

I got the "ReadAllText" from here, but it's not available to me.

I am referencing mscorlib, and I did add a "using System.IO;" but it's grayed out, while ReadAllText is fire-engine red.

Am I missing something, or do I have to skin this cat some other way in this Windows CE / Compact Framework app?

B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • 1
    Apparently all File.ReadAllText does, apart from a few null/empty checks, is calling StreamReader.ReadToEnd method, but I guess that's unavailable too. – S_F Jan 14 '15 at 01:09
  • 1
    If you look at the docos for the class ( http://msdn.microsoft.com/en-us/library/System.IO.File_methods(v=vs.90).aspx ) it shows a little mobile device icon next to the methods that are supported. – tcarvin Jan 14 '15 at 14:47

1 Answers1

3

The compact-framework edition does not implement it. The .net version, however, is simply implemented like this:

public static class File
{
    public static String ReadAllText(String path)
    {
        using (var sr = new StreamReader(path, Encoding.UTF8))
        {
            return sr.ReadToEnd();
        }
    }
}
Luke Hutton
  • 10,612
  • 6
  • 33
  • 58