J
jez
I got my upload and download function to work properly (via WiFi can
download/upload files to an IIS server). However when trying to make a third
consecutive upload I get the following timeout error : ### An unhandled
exception of type 'System.Net.WebException' occurred in System.dll.
Additional information: The operation has timed-out. ###. I supose I can
catch this with a RequestTimeOut exception but that's obviously not what I
want to do..
I checked IIS's log files. The two first uploads seem to be ok (code 200)
and the files are also uploaded correctly (as a matter of fact they're being
overwritten but that's not the problem as I even deleted the files each time
and it still didn't work). I get stuck when debugging at req.GetResponse().
Any idea of what it could be ?
thanks !
jez
ps: I got the code of the MSDN website (an article by Jim Wilson, October
2003)
###
Here's the code :
private void uploadFile(string localFile, string uploadUrl)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uploadUrl);
req.Method="PUT";
req.AllowWriteStreamBuffering = true;
//Retrieve request stream
Stream reqStream = req.GetRequestStream();
//open the local file
FileStream rdr = new FileStream(localFile, FileMode.Open);
//Allocate byte buffer to hold file contents
byte[] inData = new byte[4096];
//loop through the local file reading each data block and writing to the
request stream buffer
int bytesRead = rdr.Read(inData, 0, inData.Length);
while (bytesRead > 0)
{
reqStream.Write(inData, 0, bytesRead);
bytesRead = rdr.Read(inData, 0, inData.Length);
}
rdr.Flush();
rdr.Close();
rdr = null;
reqStream.Flush();
reqStream.Close();
reqStream = null;
req.GetResponse();
req = null;
}
download/upload files to an IIS server). However when trying to make a third
consecutive upload I get the following timeout error : ### An unhandled
exception of type 'System.Net.WebException' occurred in System.dll.
Additional information: The operation has timed-out. ###. I supose I can
catch this with a RequestTimeOut exception but that's obviously not what I
want to do..
I checked IIS's log files. The two first uploads seem to be ok (code 200)
and the files are also uploaded correctly (as a matter of fact they're being
overwritten but that's not the problem as I even deleted the files each time
and it still didn't work). I get stuck when debugging at req.GetResponse().
Any idea of what it could be ?
thanks !
jez
ps: I got the code of the MSDN website (an article by Jim Wilson, October
2003)
###
Here's the code :
private void uploadFile(string localFile, string uploadUrl)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uploadUrl);
req.Method="PUT";
req.AllowWriteStreamBuffering = true;
//Retrieve request stream
Stream reqStream = req.GetRequestStream();
//open the local file
FileStream rdr = new FileStream(localFile, FileMode.Open);
//Allocate byte buffer to hold file contents
byte[] inData = new byte[4096];
//loop through the local file reading each data block and writing to the
request stream buffer
int bytesRead = rdr.Read(inData, 0, inData.Length);
while (bytesRead > 0)
{
reqStream.Write(inData, 0, bytesRead);
bytesRead = rdr.Read(inData, 0, inData.Length);
}
rdr.Flush();
rdr.Close();
rdr = null;
reqStream.Flush();
reqStream.Close();
reqStream = null;
req.GetResponse();
req = null;
}