public class getfile : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
try
{
int fileId;
int.TryParse(context.Request.QueryString[Timeline.Constants.QUERYSTRING_FILEID], out fileId);
MyFileClass file = new MyFileClass(fileId); //retrieve file info
context.Response.Clear();
context.Response.ContentType = "application/octet-stream";
byte[] fileSize = File.ReadAllBytes(file.PhysicalPath);
context.Response.AddHeader("Content-Length", fileSize.Length.ToString());
fileSize = null;
context.Response.AppendHeader("Content-Disposition", string.Format("attachment;filename={0}", file.Filename));
context.Response.WriteFile(file.PhysicalPath);
context.ApplicationInstance.CompleteRequest();
}
catch (Exception ex)
{
context.Response.Write(ex.Message);
}
context.Response.End();
}
public bool IsReusable
{
get
{
return true;
}
}
}
Thursday, July 23, 2009
Download file HttpHandler
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment