I'm writing the following code to read in a file from the filepath given (Using VS2010 & C#):
static void Main(string[] args)
{
string temp;
string path = "C:\Windows\Temp\fmfozdom.5hn.rdl";
using(FileStream stream = new FileStream(path, FileMode.Open))
{
StreamReader r = new StreamReader(stream);
temp = r.ReadToEnd();
}
Console.WriteLine(temp);
}
The compiler is complaining about the following line:
string path = "C:\Windows\Temp\fmfozdom.5hn.rdl";
It gives the message: Unrecognised escape sequence at \W and \T
What am I doing incorrectly?
You can use a verbatim string literal:
string path = @"C:\Windows\Temp\fmfozdom.5hn.rdl";
Either that, or escape the \
character:
string path = "C:\\Windows\\Temp\\fmfozdom.5hn.rdl";
The problem with your current code is that the \
is the escape sequence in the string and \W
, \T
are unknown escapes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With