Solved

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

Posted on 2010-09-21
7
2,078 Views
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.
www.awebsite.com/billimages is defined as a virtual directory in IIS as an application.
I tried it with "Read" and "Directory Browsing" turned on.
DocPath = "http://www.awebsite.com/billimages/<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

            Else

                Me.GetFBPDF.Visible = False

                FBFile = False

            End If

Open in new window

0
Comment
Question by:mkacos
  • 4
  • 2
7 Comments
 
LVL 3

Expert Comment

by:_bmendoza
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"
0
 
LVL 5

Accepted Solution

by:
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

http://www.vbdotnetheaven.com/UploadFile/bfarley/FileDownload04182005043858AM/FileDownload.aspx
http://www.vbforums.com/showthread.php?t=396260
http://blogs.techrepublic.com.com/programming-and-development/?p=695

I'm pressed for time to try knock together the code but you should get the direction...
0
 
LVL 1

Author Comment

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

0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 1

Author Comment

by:mkacos
ID: 33734641
Ina_Don

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 = "http://www.AWebSite.com/BillImages/" & Carrier & "/" & format(Shipdate, "yyyyMM") & "/" & PRO & ".pdf"

            Dim FileisThere As Boolean = False



            Dim imageAddress As String = String.Empty

            Dim filename As String = String.Empty

            Try

                Dim fileReader As New WebClient()

                imageAddress = DocPath

                filename = format(Date.now, "MMddhhss") & ".tmp"

                If Not (System.IO.File.Exists("c:\windows\web\" + filename)) Then

                    fileReader.DownloadFile(imageAddress, "c:\" + filename)

                End If

                System.io.file.delete("c:\windows\temp\" + filename)

                Fileisthere = True

            Catch ex As HttpListenerException

                Fileisthere = False

            Catch ex As Exception

                Fileisthere = False

            End Try

Open in new window

0
 
LVL 1

Author Closing Comment

by:mkacos
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.
0
 
LVL 5

Expert Comment

by:ina_don
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!!?
0
 
LVL 1

Author Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need to pass a connection through class/Method 1 39
Error in page 3 45
Data is not showing from images 15 37
What .NET URL re-routing tool did I use? 2 36
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

912 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now