Solved

Web Page Auto Access to download file

Posted on 2001-07-28
18
186 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
[X]
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
  • 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
Industry Leaders: 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses
Course of the Month4 days, 17 hours left to enroll

635 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