Solved

Web Page Auto Access to download file

Posted on 2001-07-28
18
182 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSRS expression Issue finding a string 10 99
How to debug this code 7 65
Using "ScreenUpdating" 6 83
MS Date Picker 64 bit 32 bit issue 12 63
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

680 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