saving image from web

L

Laszlo Csabi

Hi guys,

Anyone knows about how to save a picture from a html page to the hard disk
either in C# or VB.NET? What I have done so far is the following and it
doesn't work. I got an empty image created on the HDD. But if you click on
the following link it gives you the gif picture.

_webRequest =
CType(Net.WebRequest.Create("http://wdz.whereis.com.au/gns?user=demo&pass=de
mo&geolang=en&function=map&mode=server_1.2&wgs84x1y1=-37.82013035956316|144.
98320052639244&radius=800&width=400&height=400&format=gif&nourl=1"),
Net.HttpWebRequest)

_webResponse = CType(_webRequest.GetResponse(), Net.HttpWebResponse)
_stream = _webResponse.GetResponseStream

Dim inBuf(100000) As Byte
Dim bytesToRead As Integer = CInt(inBuf.Length)
Dim bytesRead As Integer = 0

While bytesToRead > 0
Dim n As Integer = _stream.Read(inBuf, bytesRead, bytesToRead)
If n = 0 Then
Exit While
End If
bytesRead += n
bytesToRead -= n
End While

If Not IO.Directory.Exists(Me.GiveFilePath) = True Then
IO.Directory.CreateDirectory(Me.GiveFilePath)
End If

_fileStream = New IO.FileStream(Me.GiveFilePath & "\map.gif",
IO.FileMode.OpenOrCreate, IO.FileAccess.Write)
_fileStream.Write(inBuf, 0, bytesRead)

_webResponse.Close()
_fileStream.Close()


Thanks

Laszlo
 
F

Fergus Cooney

Hi Laszlo,

Brunton Avenue and Wellington Parade - no problem. All I added to your
code were the 'Dim As Whatever's and hardcoded a file path. It worked
perfectly. Nothing looks obviously wrong.

Regards,
Fergus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top