/// <summary>
    /// 下载文件
    /// </summary>
    public class DownloadController : ApiController
    {
        /// <summary>
        /// 下载文件
        /// </summary>
        /// <returns></returns>      
        public async Task<HttpResponseMessage> Get()
        {
            try
            {
                string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Export\\list.txt");
                if (!string.IsNullOrWhiteSpace(path) && File.Exists(path))
                {
                    
                    string filename = Path.GetFileName(path);
                    var stream = new FileStream(path, FileMode.Open);
                    HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.OK)
                    {
                        Content = new StreamContent(stream)
                    };
                    resp.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                    {
                        FileName = filename
                    };
                    resp.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                    resp.Content.Headers.ContentLength = stream.Length;
                  
                    return await Task.FromResult(resp);
                }
            }
            catch (Exception ex)
            {
            }
            return new HttpResponseMessage(HttpStatusCode.NoContent);
        }
    }

最新文章

  1. 在Win7 64位操作系统下安装Oracle 10g
  2. 中医与DBA
  3. poj 2553 The Bottom of a Graph
  4. HDU 5762 Teacher Bo (暴力)
  5. linux下eclipse的安装
  6. (iOS)Storyboard/xib小技巧
  7. js的双等号类型转换
  8. javascript如何创建一个换行节点
  9. 关于tomcat和jetty的乱码问题
  10. python学习之时间处理
  11. Java程序设计(第二版)复习 第三章
  12. PostgreSQL安装和使用
  13. div 光标处插入内容
  14. plaidctf-2016 Pwn试题小结
  15. gradle build scan
  16. aria2自动更新BT Tracker服务器列表脚本
  17. 通过完整示例来理解如何使用 epoll
  18. Cocos2d-x-Lua (2.x)脚本开发之 Lua语言基础
  19. MySQL:管理MySQL、事务(三)
  20. insert失败自动执行update(duplicate先insert)

热门文章

  1. zabbix监控Windows-server
  2. 网关 整理 fastcgi wsgi
  3. [dpdk][kni] dpdk kernel network interface
  4. LeetCode 349 Intersection of Two Arrays 解题报告
  5. activemq安装使用教程
  6. @media screen and (max-width: 960px)与@media (max-width: 960px) 有screen与没有screen的区别
  7. Appium环境配置(二)
  8. Advising controllers with the @ControllerAdvice annotation
  9. more 命令
  10. 预见2019吴晓波年终秀演讲PPT整理