using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Configuration;
namespace example
{
public class downlaod: IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string queryFile = context.Request.QueryString["file"];
if (string.IsNullOrEmpty(queryFile))
throw new HttpException(404, null);
string file = Path.Combine(ConfigurationManager.AppSettings["upload_path"], queryFile);
if (!File.Exists(file))
{
throw new HttpException(404, null);
}
else
{
context.Response.ContentType = "application/octet-stream";
context.Response.AddHeader("content-disposition", "attachment;filename=" + queryFile);
context.Response.WriteFile(file);
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}