P
Piotrekk
Hi
My application is uploading the file to the ASP script. I am dealing
with situation where ASP script is not interested in receiving a file.
I simulate this by returning from ASP script:
protected void Page_Load(object sender, EventArgs e)
{
return
}
Then I am having difficulties in detecting such a situation on the
client side. The problem is that client is writing the file into the
buffer anyways. I tried closing Request.InputStream. Would appreciate
any help. Here is the client side code:
req = WebRequest.Create(url);
req.Method = "POST";
//Headers
req.ContentType = "multipart/form-data";
req.ContentLength = fileSize;
req.Headers.Add("Name", file.Name);
req.Headers.Add("Path", path);
req.Headers.Add("SessionID", session);
req.Timeout = int.MaxValue;
Stream stream = req.GetRequestStream();
using (BinaryWriter writer = new BinaryWriter(stream))
{
FileStream fs = new FileStream(file.FullName,
FileMode.Open);
using (BinaryReader reader = new BinaryReader(fs))
{
int i = 0;
long total = 0;
byte[] buffer = new byte[32768];
while (((i = reader.Read(buffer, 0,
buffer.Length)) > 0) && !Stop)
{
writer.Write(buffer, 0, i);
total += i;
uploadWorker.ReportProgress((int)(total *
100 / fileSize));
}
}
}
Kind Regards
PK
My application is uploading the file to the ASP script. I am dealing
with situation where ASP script is not interested in receiving a file.
I simulate this by returning from ASP script:
protected void Page_Load(object sender, EventArgs e)
{
return
}
Then I am having difficulties in detecting such a situation on the
client side. The problem is that client is writing the file into the
buffer anyways. I tried closing Request.InputStream. Would appreciate
any help. Here is the client side code:
req = WebRequest.Create(url);
req.Method = "POST";
//Headers
req.ContentType = "multipart/form-data";
req.ContentLength = fileSize;
req.Headers.Add("Name", file.Name);
req.Headers.Add("Path", path);
req.Headers.Add("SessionID", session);
req.Timeout = int.MaxValue;
Stream stream = req.GetRequestStream();
using (BinaryWriter writer = new BinaryWriter(stream))
{
FileStream fs = new FileStream(file.FullName,
FileMode.Open);
using (BinaryReader reader = new BinaryReader(fs))
{
int i = 0;
long total = 0;
byte[] buffer = new byte[32768];
while (((i = reader.Read(buffer, 0,
buffer.Length)) > 0) && !Stop)
{
writer.Write(buffer, 0, i);
total += i;
uploadWorker.ReportProgress((int)(total *
100 / fileSize));
}
}
}
Kind Regards
PK