asp.net 直接输出文件内容到客户端,并提示保存。
ResponseFile("输出的文件内容", "直接保存.txt");
protected void ResponseFile(string fileContent, string filename)
{
string coding = "gb2312";
Response.Clear();
Response.Charset = coding;
Response.Buffer = true;
this.EnableViewState = false;
Response.ContentEncoding = System.Text.Encoding.GetEncoding(coding);//.Default;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename);
Response.Write(fileContent);
Response.Flush();
Response.Close();
Response.End();
}