Solved

Web Page Auto Access to download file

Posted on 2001-07-28
18
178 Views
Last Modified: 2008-02-01
Hi
I am looking for some sample code to help me connect to a web page.
Now i have got my app working were i can connect to a specific web page if i click on a button it opens up explorer and the web page.
Now i need to automatically download the Zip file (if there is one attached to the web page) and save it to the harddrive automatically without opening explorer.

So basically i would like to click on my button and it goes and saves the zipe file from the web page.

Thanx Allot

Craig
0
Comment
Question by:CraigLazar
  • 7
  • 7
  • 3
  • +1
18 Comments
 
LVL 28

Accepted Solution

by:
AzraSound earned 250 total points
ID: 6330142
what is the zip file?  a link on the page?  is it a dynamic link that changes its name and/or URL each time you visit the page?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6330718
Good point Azra.
0
 

Expert Comment

by:tyronen
ID: 6330820

If you already know the URL of the ZipFile, the easiest way is to use the Microsoft Internet Transfer Control.  If you are using a form, check the control in the Components dialog box and add an instance to the form.  If you are using a class module or module, instantiate it with

Dim inet1 as New InetCtls.Inet

Then add code like this:

Dim bData() as Byte
bData() = inet1.OpenURL("http://www.site.com/zip_dir/zipfile.zip",icByteArray))

Open "zipfile.zip" For Binary Access Write As #1
Put #1, bData
Close #1
0
 
LVL 4

Author Comment

by:CraigLazar
ID: 6333694
Hi guys thanx for getting back to this so quick
well yes it is i think a link t the page and the file name chages from url to url
all i have at the moment is a the url to the specific web page eg www.msn.com\page1
then the zip file is there, sometimes there is not , i need to first check if there is a zip file with page then if there is be able to downlaod it - u know if u do it manually it asks you were would u like to save the file

thanx again

Craig
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6333988
if it is indeed a link on the webpage, then you can check for it by using something like:


Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal _
szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long



For i = 0 To Browser.Document.links.length - 1
   If Right$(Browser.Document.links(i).href, 3) = "zip" Then
      'download the zip
      Call URLDownloadToFile(0, Browser.Document.links(i).href, "C:\temp\file.zip", 0, 0)
   End If
Next
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6335835
Excelent code!
I think only that "for...next" should be on documentcomplete event of object Browser.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6340435
good addition Richie...and if you dont want it to execute at every page you navigate to, the DocumentComplete event exposes a URL parameter which you can check to ensure you only run the code at the desired URL.
0
 
LVL 4

Author Comment

by:CraigLazar
ID: 6351085
Hi AzraSound

I am a bit thick :)
can u clarify the code a bit more please
i would like to take it and put it in a command button
r there any ocxs in need on the form ?

thanx allot

Craig
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6351675
all you should need is a webbrowser control on your form, named Browser in my example above...


Option Explicit
Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal _
szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long


Private Sub Command1_Click()
Dim i As Integer

For i = 0 To Browser.Document.links.length - 1
  If Right$(Browser.Document.links(i).href, 3) = "zip" Then
     'download the zip
     Call URLDownloadToFile(0, Browser.Document.links(i).href, "C:\temp\file.zip", 0, 0)
  End If
Next
End Sub
0
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.

 
LVL 4

Author Comment

by:CraigLazar
ID: 6367864
HI Azrasound

i put a webbrowser on a test form called it browser
but returns this error on this line of code
object variable or With Block variable not set\
>>For i = 0 To Browser.Document.links.length - 1

so i went to my browser control in code and it does not pick up the document.links method or property

sorry am i doing something stupid here ??

thanx Craig
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6367937
has the browser fully navigated to the URL where you wish to loop through the links on the page?
0
 
LVL 4

Author Comment

by:CraigLazar
ID: 6371589
hi azra
NOt to sure waht u mean ?
but as soon as i press my command1 button on the form with the browser control on it gives me this error

:)

thanx

Craig
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6372198
What Azra said is:
You must take care that page is complete downloaded (In other words, the animation at right-top corner of your web browser is stopped) for this code to work.
0
 
LVL 4

Author Comment

by:CraigLazar
ID: 6395772
hi guys
sorry for gettting back to this question late
i will give it a bash this weekend and hopefully i can get it working :) :)
have a good one

Craig
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6397146
Not a problem...thanks for keeping us posted.
0
 
LVL 4

Author Comment

by:CraigLazar
ID: 6420432
Hi guys i trust every one is well ?

Ok Azra - i have been so busy i have not had time to get back to this
so can i accept your answer and when i get the chance and need som ehelp with the code u have submitted can i then if need be get your help on it later on ?

thanx allot

Cheers have a good weekend

Craig
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6420491
Whatever youre comfortable with Craig...no worries.
0
 
LVL 4

Author Comment

by:CraigLazar
ID: 6424039
cool by the pool
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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

932 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

13 Experts available now in Live!

Get 1:1 Help Now