<span style="font-family:FangSong_GB2312;font-size:18px;"><strong> string path = Server.MapPath("../templateExcel/附件模板.xls");
FileInfo fi = new FileInfo(path);//excelFile为文件在服务器上的地址
if (File.Exists(path))
{
Response.Clear();
Response.Buffer = true; //设置<span style="color: rgb(51, 51, 51); line-height: 24px; white-space: pre-wrap;">输出页面是否被缓冲</span>
Response.Charset = "GB2312"; //设置了类型为中文防止乱码的出现
Response.AppendHeader("Content-Disposition", String.Format("attachment;filename={0}", HttpUtility.UrlEncode("附件模板.xls"))); //定义输出文件和文件名
Response.AppendHeader("Content-Length", fi.Length.ToString());
Response.ContentEncoding = Encoding.Default;
Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
Response.WriteFile(fi.FullName);
Response.Flush();
Response.End();
}
else
ScriptManager.RegisterStartupScript(this, this.GetType(), "", "<script>alert('此模板不存在!');</script>", false);</strong></span>