confused

  • Thread starter Thread starter Luke Smith
  • Start date Start date
L

Luke Smith

why does

if (File.Exists(Server.MapPath("..\files" + counterid + ".txt")))

not cause an error, yet

if (File.Exists(Server.MapPath("..\files\" + counterid + ".txt")))

says there is a ')' expected at the end?
 
Luke said:
if (File.Exists(Server.MapPath("..\files\" + counterid + ".txt")))

says there is a ')' expected at the end?

To get a single backslash in a text string, you must either unesacpe the
entire thing:
@"..\files\" + counterid.txt + ".txt"

Or use two backslashes for every one you wish to see in the output:

"..\\files\\" + counterid + ".txt".

I normally use string.Format for this sort of thing:

Server.MapPath(string.Format(@"..\files\{0}.txt", counterid));

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
 
Luke Smith said:
why does

if (File.Exists(Server.MapPath("..\files" + counterid + ".txt")))

not cause an error, yet

if (File.Exists(Server.MapPath("..\files\" + counterid + ".txt")))

says there is a ')' expected at the end?

In strings, \f means form feed and \" means a quotation mark within a
string.

Write your \ characters double, or put @ before the opening quote to tell C#
not to process \ characters specially.
 
Back
Top