Check to see if a file exists on a virtual directory across the internet

I am trying to check if a file exists in a virtual directory.  I tried File.Exists but it always returns false.  I am trying to see if the file exists so I can turn a control on or off.  

I am using IIS 6.0, VS 2008.  

I have attached a sample of my code below. is defined as a virtual directory in IIS as an application.
I tried it with "Read" and "Directory Browsing" turned on.
DocPath = "<dir>/<YYYYMM>/filename.pdf"

If File.Exists(DocPath) Then
                Me.GetFBPdf.commandname = docpath
                Me.GetFBPDF.Text = "View the FB Docs"
                Me.GetFBPDF.Visible = True
                FBFile = True
                Me.GetFBPDF.Visible = False
                FBFile = False
            End If

Open in new window

Who is Participating?

Improve company productivity with a Business Account.Sign Up

ina_donConnect With a Mentor Commented:
If you are attempting to do this over the internet then the best thing is to attempt to download the file. A few example projects exist online that can act as a guide

I'm pressed for time to try knock together the code but you should get the direction...
do you know the physical directory of the file?
if yes please try something like.
DocPath = "C:\Inetpub\wwwroot\<dir>\<YYYYMM>\filename.pdf"
mkacosAuthor Commented:
bmendoza - The actual path is not available to the user since it is being accessed through the web.

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

mkacosAuthor Commented:

Almost works.  Actually, it works great on my developpment computer but fails on the web site.  No, it does not fail I just need to find out where I can write a file on the end users computer.    I hard coded c:\windows\temp but I do not believe my application can write to the end users file system.

I am looking for a folder I can create then delete the temp file.  Any suggestions?
' Attempt a download to see if the file exists ****************
            DocPath = "" & Carrier & "/" & format(Shipdate, "yyyyMM") & "/" & PRO & ".pdf"
            Dim FileisThere As Boolean = False

            Dim imageAddress As String = String.Empty
            Dim filename As String = String.Empty
                Dim fileReader As New WebClient()
                imageAddress = DocPath
                filename = format(, "MMddhhss") & ".tmp"
                If Not (System.IO.File.Exists("c:\windows\web\" + filename)) Then
                    fileReader.DownloadFile(imageAddress, "c:\" + filename)
                End If
      "c:\windows\temp\" + filename)
                Fileisthere = True
            Catch ex As HttpListenerException
                Fileisthere = False
            Catch ex As Exception
                Fileisthere = False
            End Try

Open in new window

mkacosAuthor Commented:
I had to add  Dim foldername As String
        Dim fs
        fs = Server.CreateObject"Scripting.FileSystemObject")
 foldername = fs.GetSpecialFolder(2).path
  fs = Nothing
to get it to find the tem path but it worked.
So are you alright now. I didn't have a chance to respond and I see you have already responded to the problem yourself!!?
mkacosAuthor Commented:
Yes, your response was very helpful.  Thanks
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.