zoukankan      html  css  js  c++  java
  • Asp.net mvc3 文件下载的实现

    1.控制器的ActionResult

      public ActionResult DownLoadFile()
            {
                string filePath = Server.MapPath("~/ResourceFile/1ef53469-cbac-4007-b40b-ae68644794e7.doc");
                return new DownloadResult(filePath, "1ef53469-cbac-4007-b40b-ae68644794e7.doc");        
            }

    2.DownLoadResult类的实现

     public class DownloadResult : ActionResult
        {
            public DownloadResult()
            {
            }

            public DownloadResult(string virtualPath,string fileDownloadName)
            {
                this.VirtualPath = virtualPath;
                this.FileDownloadName = fileDownloadName;
            }

            public string VirtualPath
            {
                get;
                set;
            }

            public string FileDownloadName
            {
                get;
                set;
            }

            public override void ExecuteResult(ControllerContext context) {
                  if (!String.IsNullOrEmpty(FileDownloadName)) {
                      context.HttpContext.Response.AddHeader("content-disposition",
                        "attachment; filename=" + this.FileDownloadName);
        }

        string filePath = this.VirtualPath;
        context.HttpContext.Response.TransmitFile(filePath);
        }

        }

  • 相关阅读:
    使用python三方库xlrd解析excel数据
    testng之listener
    使用Junit实现批量运行
    gojs绘流程图
    sqlserver
    Android学习笔记之 android:collapseColumns ,android:shrinkColumns 和stretchColumns
    myBatis oracle 与mysql自增问题
    Oracle总结
    Oracle 树操作(select…start with…connect by…prior)
    Oracle 获取当前日期及日期格式
  • 原文地址:https://www.cnblogs.com/kouhh/p/2471898.html
Copyright © 2011-2022 走看看