Re: Error in c# project: Unrecognized escape sequence

  • Thread starter Chris R. Timmons
  • 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.
 
Ad

Advertisements

Joined
Jan 2, 2007
Messages
1
Reaction score
0
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:
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top