webapi下载文件
[HttpGet] public IHttpActionResult ExportData() { ... var dt = ExcelHelper.ListToDataTable(list); var fileName = SysConfig.WebTempPath + Guid.NewGuid().ToString() + ".xls"; ExcelHelper.ExportToFile(dt,fileName);
//http://www.cnblogs.com/enternal/p/5417519.html HttpResponseMessage httpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK); FileStream fileStream = File.OpenRead(fileName); httpResponseMessage.Content = new StreamContent(fileStream); httpResponseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); httpResponseMessage.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName =HttpUtility.UrlEncode(Path.GetFileName(fileName)) }; return ResponseMessage(httpResponseMessage); }
DF1E31DE-768E-43D7-B1DB-DE10BD031E13 From:http://www.cnblogs.com/xuejianxiyang/p/7802365.html
作者:xuejianxiyang
出处:http://xuejianxiyang.cnblogs.com
关于作者:Heaven helps those who help themselves.
本文版权归原作者和博客园共有,欢迎转载,但未经原作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步