I would recommend reading the file as a byte [] and sending it with the content and content type in response, and then just execute response.binarywrite and response.flush:
Byte[] bytes = null;
try
{
if(!FileExists(_filename)) return null;
Byte[fs.Length] bytes
using(System.IO.FileStream fs = System.IO.File.Open(_file, FileMode.Open, FileAccess.Read))
{
fs.Read(bytes, 0, fs.Length);
}
}
catch(Exception ex)
{
System.Text.ASCIIEncoding oEncoder = new System.Text.ASCIIEncoding();
Byte[] bytes = oEncoder.GetBytes(ex.Message);
}
Context.Response.Buffer = false;
Context.ClearContent();
Context.ClearHeaders();
Context.ContentType = "application/octet-stream";
Context.AddHeader("Content-Length", bytes.Length.ToString());
Context.AddHeader("content-disposition", String.Format("inline; filename={0}", filename));
Context.Response.BinaryResult(bytes);
Context.Response.Flush();
Parts of the response will need to be adjusted according to your own delivery platform (separate page, in iframe, etc.). For example, you may not want ClearHeaders ().
source
share