We have an ASP page that displays product information from a database. We also have a button to download/view a related PDF file that should only appear on the page if the PDF file physically exists. We used Request.ServerVariables(“APPL_PHYSICAL_PATH”) to determine the path to check whether the file exists.
Recently we moved the folder that contained the PDF files to a different drive on the server and changed the path property of the folder in Internet Information Server (IIS). Now we can’t check for the file because the path always returns the incorrect disk drive. Any idea what we’re doing wrong? We have the pathname hard coded and we don’t want to leave it that way.
Use Server.MapPath instead of hard coding the directory path. If you know the name of the directory where the PDF file should be, you can use the Server.MapPath function to obtain the full physical path of the directory. So if you know that the PDF files will be in the PDFFILES sub directory on the Web server, use:
Dim strDirstrDir = Server.MapPath("/pdffiles")
This will return the physical DOS path to the virtual directory “/pdffiles”. This path could be for example, D:WEBSMyWebDataFilesPdfFiles. Use the value of strDir along with the FileSystemObject to check if your file exists.