求助!

mad chu 2019-01-08 04:53:46
我前端使用的vue 使用ajax调用webapi来做npoi的导出功能 导出成功之后想输出到页面 在页面下载下来 可是在生成excel后面调用以下代码完全没动静 从网上找各种解决办法 可是都没用 哪位大佬来给个建议呢 最好附上一段代码

void downloadfile(string filePath)
{
System.IO.FileInfo file = new System.IO.FileInfo(filePath);
HttpContext.Current.Response.ContentType = "application/ms-download";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Type", "application/octet-stream");
HttpContext.Current.Response.Charset = "utf-8";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(file.Name, System.Text.Encoding.UTF8));
HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
HttpContext.Current.Response.WriteFile(file.FullName);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.End();
}
...全文
95 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
WaitzoneDon 2019-01-09
  • 打赏
  • 举报
回复
先把文件保存在服务端,返回URL,如果是get请求前端直接打开调用链接即可

110,565

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧