111,126
社区成员
发帖
与我相关
我的任务
分享
protected void Button1_Click(object sender, EventArgs e)
{
//例如要下载App_Data目录下的excel文件:"excelFile.xls"
string strFileName = "excelFile";
string strFilePath = System.Web.HttpContext.Current.Server.MapPath("./App_Data/") + strFileName + ".xls";
System.IO.FileInfo file = new System.IO.FileInfo(strFilePath);
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(strFileName + ".xls"));
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName);
Response.Flush();
Response.Clear();
Response.End();
}