J
jhansl
Hello,
I am trying desperately how to find out if the bytes sent in a
Response.BinaryWrite (or bytes written to Response.OutputStream) are
ACTUALLY sent to the client. My problem is that I have files I would
like to send to client only one time, so I need to check to see that
all the bytes were actually sent to the client. As far as I can tell,
there seems to be no way of checking to see if the bytes were sent. If
I run a test and cancel the download mid-way through the transfer, the
BinaryWrite() method just returns without throwing any kind of
exception. There has to be a way to find out if the operation was
cancelled, timed out, or was incomplete. Here is my code:
private const int BUFFER_SIZE = 32768; // 32K buffer
public void ProcessRequest(HttpContext context)
{
HttpRequest Request = context.Request;
HttpResponse Response = context.Response;
try
{
string sourcePath =
ConfigurationManager.AppSettings["MasterSourcePath"];
string filename = Path.Combine(sourcePath,
"1001/1003/5000151.wma");
Response.Buffer = false;
Response.BufferOutput = false;
Response.ContentType = "audio/x-msdownload";
Response.AddHeader("Content-Disposition",
"attachment;filename=Test.wma");
Stream outstream = Response.OutputStream;
FileStream instream = new FileStream(filename,
FileMode.Open, FileAccess.Read, FileShare.Read);
byte[] buffer = new byte[BUFFER_SIZE];
int len;
while ((len = instream.Read(buffer, 0, BUFFER_SIZE)) > 0)
{
outstream.Write(buffer, 0, len);
}
outstream.Flush();
instream.Close();
}
catch (Exception ex)
{
Response.Write("Could not serve clip: " + ex.Message);
}
}
Thank You,
Josh
I am trying desperately how to find out if the bytes sent in a
Response.BinaryWrite (or bytes written to Response.OutputStream) are
ACTUALLY sent to the client. My problem is that I have files I would
like to send to client only one time, so I need to check to see that
all the bytes were actually sent to the client. As far as I can tell,
there seems to be no way of checking to see if the bytes were sent. If
I run a test and cancel the download mid-way through the transfer, the
BinaryWrite() method just returns without throwing any kind of
exception. There has to be a way to find out if the operation was
cancelled, timed out, or was incomplete. Here is my code:
private const int BUFFER_SIZE = 32768; // 32K buffer
public void ProcessRequest(HttpContext context)
{
HttpRequest Request = context.Request;
HttpResponse Response = context.Response;
try
{
string sourcePath =
ConfigurationManager.AppSettings["MasterSourcePath"];
string filename = Path.Combine(sourcePath,
"1001/1003/5000151.wma");
Response.Buffer = false;
Response.BufferOutput = false;
Response.ContentType = "audio/x-msdownload";
Response.AddHeader("Content-Disposition",
"attachment;filename=Test.wma");
Stream outstream = Response.OutputStream;
FileStream instream = new FileStream(filename,
FileMode.Open, FileAccess.Read, FileShare.Read);
byte[] buffer = new byte[BUFFER_SIZE];
int len;
while ((len = instream.Read(buffer, 0, BUFFER_SIZE)) > 0)
{
outstream.Write(buffer, 0, len);
}
outstream.Flush();
instream.Close();
}
catch (Exception ex)
{
Response.Write("Could not serve clip: " + ex.Message);
}
}
Thank You,
Josh