日期:2014-05-17  浏览次数:20923 次

C#导出Excel,服务端已经生成Excel文件,不下载。
本人做了个C#导出Excel的功能,
架构师用的EasyUI,Jq去访问的后台,后台已经生成所需的Excel,但是页面就是不提示下载,哪位大侠知道,不妨指点一二。
以下是输出的代码:

System.Web.UI.Page page = new System.Web.UI.Page();
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Buffer = true;
            HttpContext.Current.Response.ContentType = "application/ms-excel";
            HttpContext.Current.Response.ContentEncoding = Encoding.Default;
            HttpContext.Current.Response.Charset = "GB2312";
            HttpContext.Current.Response.AddHeader("Content-Length", fileInfo.Length.ToString());
            HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + page.Server.UrlEncode(fileInfo.Name));
            //HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileInfo.Name);
            HttpContext.Current.Response.WriteFile(fileInfo.FullName);
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();


fileInfo.FullName是文件在服务器上的物理路径,已经确认路径是对的了。
后台的Excel也已经生成。
其实这也能算是文件不能下载的问题。
请各位大侠多指教
C# Excel 下载 文件 EasyUI

------解决方案--------------------
 哦,你确定这样能下载文件?

反正我是没成功过,你把这段改成window.open("../Ashx/ExportExcel.ashx?excelType=user");试试。