Trying to save downloaded Image... HELP

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

HI,

I'm trying to save an image that I download via a URL. The code below is
what I have so far, but I am getting stuck with saving it. I am using CF 1.1.

Any help would be appricated.

CODE STARTS HERE....
Dim objResult As WebResponse
Dim objRequest As WebRequest
objRequest = WebRequest.Create(strUrl)
objRequest.Timeout = 900000
objResult = objRequest.GetResponse

Dim objReceiveStream As Stream = objResult.GetResponseStream()

' BUILD FILENAME
Dim strFilename As String = Me.tbFileName.Text & "-" & intLoop & ".jpg"

' SAVE ITEM
Dim objFile As New FileStream(strFilename, FileMode.Create)

Dim intByte As Integer

Do

intByte = objReceiveStream.ReadByte

Loop Until intByte = -1

objFile.Close()

objReceiveStream.Close()

objResult.Close()

objRequest.Abort()
 
Here's a snip from one of my applications:

Dim reader As BinaryReader = New BinaryReader(dataStream)
Dim finished As Boolean = False
Const BufferSize As Integer = 1024
Dim buffer() As Byte = New Byte((BufferSize) - 1) {}
Dim dataRead As Integer = 0

Do
Try
dataRead = reader.Read(buffer, 0, BufferSize)
If (dataRead = 0) Then
finished = True
End If
localStream.Write(buffer, 0, dataRead)
bytesReceived = (bytesReceived + dataRead)
Catch exception As ThreadAbortException
Console.WriteLine(exception.ToString)
localStream.Close()
dataStream.Close()
SetStatus(exception.Message, StatusCodes.ErrorStatus)
Catch ex As Exception
localStream.Close()
dataStream.Close()
SetStatus(ex.Message, StatusCodes.ErrorStatus)
threadAbort = True
End Try

Loop While finished = False And Not threadAbort
 
Hi Alex,

Thanks for the reply. Intgrated some of your code and it works nicely.
Thanks very much for the Help.
 
Back
Top