using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
namespace WebPage
{
/// <summary>
/// FileDownResponse 的摘要说明
/// </summary>
public class FileDownResponse : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string filename = context.Request["filename"];
if (string.IsNullOrEmpty(filename))
{
context.Response.End();
return;
}
string strPath = context.Server.MapPath("~/") + filename;
context.Response.AddHeader("Content-disposition", "attachment; filename=" + filename);
context.Response.WriteFile(strPath);
//StreamWriter writer = new StreamWriter(context.Response.OutputStream);
//writer.WriteLine("This is the first line from server");
//writer.WriteLine("This is the second line from server");
//writer.WriteLine("End of text from server");
//writer.Close();
context.Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
}
}