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