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

Posted on 2010-09-21
Last Modified: 2013-11-11
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

Question by:mkacos
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2

Expert Comment

ID: 33729775
do you know the physical directory of the file?
if yes please try something like.
DocPath = "C:\Inetpub\wwwroot\<dir>\<YYYYMM>\filename.pdf"

Accepted Solution

ina_don earned 500 total points
ID: 33730865
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...

Author Comment

ID: 33734597
bmendoza - The actual path is not available to the user since it is being accessed through the web.

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.


Author Comment

ID: 33734641

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


Author Closing Comment

ID: 33734995
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.

Expert Comment

ID: 33742067
So are you alright now. I didn't have a chance to respond and I see you have already responded to the problem yourself!!?

Author Comment

ID: 33743645
Yes, your response was very helpful.  Thanks

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you considered what group policies are backwards and forwards compatible? Windows Active Directory servers and clients use group policy templates to deploy sets of policies within your domain. But, there is a catch to deploying policies. The…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question