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
          主站蜘蛛池模板: 泰和县| 丰城市| 和田县| 黎川县| 陈巴尔虎旗| 新宾| 杭州市| 新竹县| 古田县| 天等县| 永昌县| 如皋市| 莱州市| 抚远县| 武义县| 平阳县| 旅游| 乐业县| 潢川县| 韶关市| 建平县| 张北县| 峨眉山市| 永安市| 巴楚县| 申扎县| 商水县| 阿勒泰市| 徐闻县| 同心县| 锡林浩特市| 望都县| 莱西市| 汶川县| 通州区| 陈巴尔虎旗| 沂源县| 三门县| 伊春市| 平原县| 泽库县|