http download

  • Thread starter Thread starter belgie
  • Start date Start date
B

belgie

How can I retrieve an image (.jpg) from a web site using http with VB
dotnet?

thanks
Bill
 
Hi Belgie,

Have a look to webclient.downloadfile

Very simple with that

I hope this helps?

Cor
 
Hi Ken,

Mostly I like that, but for this I think it is not that good.
As far as I know will the gif loose parts of the pixels doing this.
(If I am wrong in the last sentence, it is only what I did read)

:-)

Cor
 
When I try downloadfile, I always get

"An unhandled exception of type 'System.Net.WebException' occurred in
system.dll
Additional information: The remote server returned an error: (404) Not
Found."

I used the example from the documentation verbatim. Is this a LAN/firewall
issue possibly? I have tried to download image files which I can see in a
browser.


Function WebClientTest()
Dim remoteUri As String =
"http://www.contoso.com/library/homepage/images/"
Dim fileName As String = "ms-banner.gif"
Dim myStringWebResource As String = Nothing
' Create a new WebClient instance.
Dim myWebClient As New WebClient()
' Concatenate the domain with the Web resource filename. Because
DownloadFile
'requires a fully qualified resource name, concatenate the domain
with the Web resource file name.
myStringWebResource = remoteUri + fileName
Console.WriteLine("Downloading File ""{0}"" from ""{1}"" ......." +
ControlChars.Cr + ControlChars.Cr, fileName, myStringWebResource)
' The DownloadFile() method downloads the Web resource and saves it
into the current file-system folder.
myWebClient.DownloadFile(myStringWebResource, fileName)
Console.WriteLine("Successfully Downloaded file ""{0}"" from
""{1}""", fileName, myStringWebResource)
Console.WriteLine((ControlChars.Cr + "Downloaded file saved in the
following file system folder:" + ControlChars.Cr + ControlChars.Tab +
Application.StartupPath))
End Function
 
Hi Belgie,

I know minimum two situations that I cannot get all files.
Situation one, the image is on a protected part of the disk (the page
can read them but you not)
Situation two, the image is first streamwritted from a database to a
tempory internet page.

Till now I could not get a method to get them,

To get the first one is very difficult and I think illegal because it is in
my opinion a kind of hacking.

For the second situaton I think that it maybe is possible as you open in the
same time the corresponding webpage, but I never tried.

Cor
 
This works with no problem in VB6, with a INET control on a form, with the
same URL which doesn't work with the VB dotNet WebClient:

Public Function GetInternetFile(Inet1 As Inet, myURL As String, DestDIR As
String) As Boolean

Dim myData() As Byte
Dim intFree As Integer

If Inet1.StillExecuting = True Then Exit Function
myData() = Inet1.OpenURL(myURL, icByteArray)

intFree = FreeFile

Open DestDIR For Binary Access Write As #intFree
' Open App.Path & "\test.htm" For Binary Access Write As #intFree
Put #intFree, , myData()
Close #intFree
End Function

Thanksfor your help!
Bil
 
Hi,

Maybe they were updating the weather map when you tried it.

Ken
-------------------
 
Back
Top