Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Active Server Pages (ASP)
Expertise: Beginner
Feb 25, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Determine if a PDF File Exists From ASP


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 strDir
strDir = Server.MapPath("/pdffiles")

This will return the physical DOS path to the virtual directory "/pdffiles". This path could be for example, D:\WEBS\MyWeb\DataFiles\PdfFiles. Use the value of strDir along with the FileSystemObject to check if your file exists.

DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date