T
TEAMBEER
Hi all,
I am trying to download an image from an url and save this image to a file.
The following procedure saves a file with 0 bytes. why??
Public Sub LoadImageFromUrl(ByVal Url As String)
Dim srv_request As System.Net.WebRequest =
System.Net.WebRequest.Create(Url)
Dim srv_response As System.Net.WebResponse = srv_request.GetResponse()
Dim ImgStream As IO.Stream
Dim buf(8192) As Byte
Dim read As Integer
ImgStream = srv_response.GetResponseStream()
Dim Image As System.Drawing.Image = New System.Drawing.Bitmap(ImgStream)
Dim fs As IO.FileStream
fs = New IO.FileStream("\Temp\test.jpg", IO.FileMode.Create,
IO.FileAccess.Write)
Do While read <> 0
read = ImgStream.Read(buf, 0, buf.Length)
If read <= 0 Then
Exit Do
End If
fs.Write(buf, 0, read)
Loop
fs.Close()
End Function
THANKS,
Herwig
I am trying to download an image from an url and save this image to a file.
The following procedure saves a file with 0 bytes. why??
Public Sub LoadImageFromUrl(ByVal Url As String)
Dim srv_request As System.Net.WebRequest =
System.Net.WebRequest.Create(Url)
Dim srv_response As System.Net.WebResponse = srv_request.GetResponse()
Dim ImgStream As IO.Stream
Dim buf(8192) As Byte
Dim read As Integer
ImgStream = srv_response.GetResponseStream()
Dim Image As System.Drawing.Image = New System.Drawing.Bitmap(ImgStream)
Dim fs As IO.FileStream
fs = New IO.FileStream("\Temp\test.jpg", IO.FileMode.Create,
IO.FileAccess.Write)
Do While read <> 0
read = ImgStream.Read(buf, 0, buf.Length)
If read <= 0 Then
Exit Do
End If
fs.Write(buf, 0, read)
Loop
fs.Close()
End Function
THANKS,
Herwig