Re: Error in c# project: Unrecognized escape sequence

  • Thread starter Thread starter Chris R. Timmons
  • Start date Start date
C

Chris R. Timmons

Svt said:
Hello,
I am creating web service to save file document and I
need to specify <file path>. What is the correct syntax
for it?
It should be:
string sFile = "<file path>";
I tried:
string sFile = "C:\MyDocuments\test_app.txt\";
and I get an error: Unrecognized escape sequence.

A single backslash in a C# string is interpreted as an escape
sequence:

http://msdn.microsoft.com/library/en-
us/csspec/html/vclrfcsharpspec_2_4_4_5.asp

If you want C# to treat the backslash character as a literal, either
double up the backslash:

string sFile = "C:\\MyDocuments\\test_app.txt\\";

or prepend the string with the @ character:

string sFile = @"C:\MyDocuments\test_app.txt\";


Hope this helps.

Chris.
 
Progressing into C# & ASP.NET 2.0

Hi,

This reply has helped me in 2007. I am currently trying to learn C# and ASP.NET 2.0 and this was the first problem I had in 2007. Thanks for the reply.

Cheers

MARK
 
Last edited:
Back
Top