K
Ken Wilson
I have created a utility that enables my clients, who use Pocket PCs in the
field, to be able to upload files to a web server (mainly for pictures -
..jpg - they take for their business). The utility works fine... the first
time... and the second time... but times out the third time (and subsequent
times). Here is a sample of code:
Dim myStream As System.IO.Stream
Dim fInfo As System.IO.FileInfo
Dim myWebRequest As System.Net.HttpWebRequest
Dim binFile() As Byte
Dim mFileLen As Long
Dim sr As System.IO.FileStream
myWebRequest = CType(System.Net.WebRequest.Create(ServerUploadFolder &
UniqueFileName), System.Net.HttpWebRequest)
fInfo = New System.IO.FileInfo(myFile)
mFileLen = fInfo.Length
If mFileLen > 0 Then
ReDim binFile(mFileLen)
sr = System.IO.File.OpenRead(myFile)
sr.Read(binFile, 0, mFileLen)
sr.Close()
myWebRequest.KeepAlive = False
myWebRequest.Method = "PUT"
myWebRequest.ContentLength = binFile.Length
myWebRequest.Timeout = 30000
Try
myStream = myWebRequest.GetRequestStream ' It fails the 3rd
time on this line
myStream.Write(binFile, 0, binFile.Length)
myStream.Close()
myStream = Nothing
Catch
ErrMsg = Err.Description
End Try
End If
fInfo = Nothing
myWebRequest = Nothing
Even after closing the stream and setting it and the HttpWebRequest to
Nothing, I continue to get a timeout when trying:
myStream = myWebRequest.GetRequestStream
As I said... it works fine the first two times. If I close the application
and run it again, I have two more times it works before failing on the third
again.
Any clues anyone?
field, to be able to upload files to a web server (mainly for pictures -
..jpg - they take for their business). The utility works fine... the first
time... and the second time... but times out the third time (and subsequent
times). Here is a sample of code:
Dim myStream As System.IO.Stream
Dim fInfo As System.IO.FileInfo
Dim myWebRequest As System.Net.HttpWebRequest
Dim binFile() As Byte
Dim mFileLen As Long
Dim sr As System.IO.FileStream
myWebRequest = CType(System.Net.WebRequest.Create(ServerUploadFolder &
UniqueFileName), System.Net.HttpWebRequest)
fInfo = New System.IO.FileInfo(myFile)
mFileLen = fInfo.Length
If mFileLen > 0 Then
ReDim binFile(mFileLen)
sr = System.IO.File.OpenRead(myFile)
sr.Read(binFile, 0, mFileLen)
sr.Close()
myWebRequest.KeepAlive = False
myWebRequest.Method = "PUT"
myWebRequest.ContentLength = binFile.Length
myWebRequest.Timeout = 30000
Try
myStream = myWebRequest.GetRequestStream ' It fails the 3rd
time on this line
myStream.Write(binFile, 0, binFile.Length)
myStream.Close()
myStream = Nothing
Catch
ErrMsg = Err.Description
End Try
End If
fInfo = Nothing
myWebRequest = Nothing
Even after closing the stream and setting it and the HttpWebRequest to
Nothing, I continue to get a timeout when trying:
myStream = myWebRequest.GetRequestStream
As I said... it works fine the first two times. If I close the application
and run it again, I have two more times it works before failing on the third
again.
Any clues anyone?