using System.Web;
          using System.Web.Mvc;

          namespace RCRS.WebApp.LG.DataExchange.Web
          {
              //----------------------------------------------------
              /// <summary>
              
          /// FilePathResult拡張クラスです。
              
          /// ファイル名が文字化けするため対応しました。
              
          /// 巨大なサイズファイルDownload時エラー対応しました。
              
          /// </summary>
              //----------------------------------------------------
              public class FilePathResultEx : FilePathResult
              {
                  //----------------------------------------------------
                  /// <summary>
                  
          /// FilePathResultExの処理です。(TODO:要処理確認)
                  
          /// </summary>
                  
          /// <param name="fileName"></param>
                  
          /// <param name="contentType"></param>
                  
          /// <param name="fileDownloadName"></param>
                  //----------------------------------------------------
                  public FilePathResultEx(string fileName, string contentType, string fileDownloadName) : base(fileName, contentType)
                  {
                      base.FileDownloadName = fileDownloadName;
                  }

                  //----------------------------------------------------
                  /// <summary>
                  
          /// ExecuteResultの処理です。 
                  
          /// ファイル名が文字化けするため対応しました。
                  
          /// 巨大なサイズファイルDownload時エラー対応しました。
                  
          /// </summary>
                  
          /// <param name="context"></param>
                  //----------------------------------------------------
                  public override void ExecuteResult(ControllerContext context)
                  {
                      var fileName = FileDownloadName;
                      fileName = HttpUtility.UrlEncode(fileName).Replace("+""%20");
                      var response = context.HttpContext.Response;

                      response.ContentType = ContentType;
                      response.AddHeader("content-disposition", "attachment; filename=" + fileName);
                      response.Buffer = false;
                      response.TransmitFile(FileName);
                  }
              }
          }

          public ActionResult DownloadFileByPath(string path, string title)
                  {
                      var result = new FilePathResultEx(path, "application/octet-stream", path);
                      result.FileDownloadName = title;

                      return result;
                  }






          posted on 2017-05-17 10:52 Ying-er 閱讀(289) 評論(0)  編輯  收藏 所屬分類: .Net
          主站蜘蛛池模板: 大庆市| 伊宁县| 临猗县| 汉源县| 盐亭县| 徐闻县| 内黄县| 麻栗坡县| 宁都县| 漯河市| 永靖县| 桦甸市| 平阴县| 洛隆县| 尉犁县| 和政县| 南宁市| 稻城县| 罗定市| 凤台县| 临猗县| 临泽县| 江孜县| 郸城县| 界首市| 米脂县| 灵山县| 金乡县| 萝北县| 晋宁县| 余江县| 佛坪县| 怀来县| 重庆市| 高碑店市| 宁南县| 萨嘎县| 屏边| 饶河县| 上虞市| 浦江县|