Dear Sirs,
When I try to download large documents I receive the following error
"unable to read data from the transport connection". How can I solve this?
Regards,
Yahya
Private Sub DownloadImage(ByVal strSrcURI As String, ByVal localfilepath As
String, ByVal BufferSize As Integer)
Dim buffers() As Byte
Dim MyCredentialCache As System.Net.CredentialCache
ReDim buffers(BufferSize)
Dim wr As WebRequest = WebRequest.Create(strSrcURI)
' This stream does not support seeking, so it cannot return length.
' so allocate enough memory to save the binary image data.
MyCredentialCache = New System.Net.CredentialCache
MyCredentialCache.Add(New System.Uri(strSrcURI), _
"NTLM", _
New System.Net.NetworkCredential(strUserName, strPassword, strDomain) _
)
' Create the HttpWebRequest object.
wr = CType(System.Net.WebRequest.Create(strSrcURI), _
System.Net.HttpWebRequest)
' Add the network credentials to the request.
wr.Credentials = MyCredentialCache
Dim stream As Stream = wr.GetResponse().GetResponseStream()
Dim BytesToRead As Integer = CType(buffers.Length, Integer)
Dim BytesRead As Integer = 0
Dim n As Integer = 0
Do
n = stream.Read(buffers, BytesRead, BytesToRead)
BytesToRead -= n
BytesRead += n
Loop While n > 0
stream.Close()
Dim fs As FileStream = New FileStream(localfilepath, FileMode.Create)
fs.Write(buffers, 0, BytesRead)
fs.Close()
End Sub