Problem with inherited code - fsoFile.FileExists

Discussion in 'C#' started by maz, Sep 7, 2006.

  1. #1
    :confused:



    If Trim(rstCatItems.Fields("CatNotes") <> "") Then
                If fsoFile.FileExists(Left(Server.MapPath(Request.ServerVariables("SCRIPT_NAME")),Len(Server.MapPath(Request.ServerVariables("SCRIPT_NAME")))-15) + "images\" & Request.QueryString("CatCode") & ".jpg") = True Then %>
                  <textarea rows="10" name="CatNotes" cols="34" style="font-family: MS Sans Serif"><%= rstCatItems.Fields("CatNotes") %></textarea>
    Code (markup):
    Can someone suggest what the "-15" number is if

    If UCase(Right(Trim(Request.ServerVariables("SCRIPT_NAME")), 10)) = "#.ASP" Or _
           UCase(Right(Trim(Request.ServerVariables("SCRIPT_NAME")), 13)) = "#.ASP" Or _
           UCase(Right(Trim(Request.ServerVariables("SCRIPT_NAME")), 13)) = "#.ASP" Or _
           UCase(Right(Trim(Request.ServerVariables("SCRIPT_NAME")), 9)) = "#.ASP" Or _
           UCase(Right(Trim(Request.ServerVariables("SCRIPT_NAME")), 15)) = "#.ASP" Or _
           UCase(Right(Trim(Request.ServerVariables("SCRIPT_NAME")), 12)) = "#" Then
    Code (markup):

     
    maz, Sep 7, 2006 IP
  2. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #2
    Len( Server.MapPath( Request.ServerVariables("SCRIPT_NAME") ) ) -15

    First it gets the Script_Name, then it finds the real path of it (like "C:/inetpub/wwwroot/hello/") then the Len gets the Length of that string

    so it would be the length of C:/inetpub/wwwroot/hello/ - which is 26 (26 characters in that string)

    Then it minuses 26 - 15 which equals 11
     
    ccoonen, Sep 7, 2006 IP
  3. maz

    maz Banned

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I think I got the problem

    thanks for the pointer

    -15 was counting the filename characters, and deducting. However, I changed the file name and added a _2 to the file name, and as such -15 would change to -17, without this change the path to the right directory could not be established.

    So I need to change -15 to -17!:eek:

    Apparently, there is a better way, and I will post it later

    Thanks
     
    maz, Sep 8, 2006 IP
  4. maz

    maz Banned

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Apparently, this does exaclty the same, but with no need to specify a num

    response.write

    (Server.MapPath(Request.ServerVariables("SCRIPT_NAME")))

    response.write

    (left(Server.MapPath(Request.ServerVariables("SCRIPT_NAME")), InstrRev(Server.MapPath(Request.ServerVariables("SCRIPT_NAME")), "\")))


    InstrRev the script name....

    :rolleyes:
     
    maz, Sep 8, 2006 IP