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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM