confused

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Luke Smith

    #1

    confused

    why does

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

    not cause an error, yet

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

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


  • Frank Oquendo

    #2
    Re: confused

    Luke Smith wrote:
    [color=blue]
    > if (File.Exists(Se rver.MapPath(". .\files\" + counterid + ".txt")))
    >
    > says there is a ')' expected at the end?[/color]

    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}.t xt", counterid));

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


    (Pull the pin to reply)


    Comment

    • Michael A. Covington

      #3
      Re: confused


      "Luke Smith" <luke.smith99@b tinternet.com> wrote in message
      news:%2305KlPit DHA.2088@TK2MSF TNGP09.phx.gbl. ..[color=blue]
      > why does
      >
      > if (File.Exists(Se rver.MapPath(". .\files" + counterid + ".txt")))
      >
      > not cause an error, yet
      >
      > if (File.Exists(Se rver.MapPath(". .\files\" + counterid + ".txt")))
      >
      > says there is a ')' expected at the end?[/color]

      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.


      Comment

      Working...