Solved

Web Page Auto Access to download file

Posted on 2001-07-28
18
177 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

760 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

20 Experts available now in Live!

Get 1:1 Help Now