Problem with server.mappath

Discussion in 'C#' started by soulfly73, May 9, 2007.

  1. #1
    Hello All,

    I hope someone can help me with the following.

    In my ASP script I want to check if a certain file exists on the webserver. Therefore I use a script with an function that will check the file in question.

    Now the funny thing is that if the file to check is in the same directory where the ASP script is that it works fine, when it is in another directory (level) it wont work. Can anyone tell me what I';m doing wrong?

    Here's the code:

    <% Dim FileName

    FileName = MyRecordSet("articlearticlenumber") & ".pdf"

    'This one wont work
    FileName = Server.MapPath("/") & "</>" & "/files/ArticleManuals/" & FileName

    'This one works.
    FileName = (Server.MapPath(FileName))



    If IsFileExists(FileName) = True Then



    %>


    'This is the function part

    ' **********************************
    ' Function to check file Existance
    ' **********************************
    Function IsFileExists(byVal FileName)

    If FileName = "" Then
    IsFileExists = False
    Exit Function
    End If

    Dim objFSO

    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

    If (objFSO.FileExists( FileName )) = True Then
    IsFileExists = True
    Else
    IsFileExists = False
    End If

    Set objFSO = Nothing
    End Function
    %>


    The ASP script is in the following directory

    C:\webserver\Site\asppage.asp

    The file to check is in the following directory

    C:\webserver\site\sitefiles\manuals


    Thanks again,

    Peter
     
    soulfly73, May 9, 2007 IP
  2. ellict

    ellict Peon

    Messages:
    91
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try to change:

    FileName = Server.MapPath("/") & "</>" & "/files/ArticleManuals/" & FileName

    with just

    FileName = Server.MapPath("/files/ArticleManuals/" & FileName)
     
    ellict, May 9, 2007 IP
  3. soulfly73

    soulfly73 Guest

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks that worked!!!
     
    soulfly73, May 9, 2007 IP