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 阅读(263) 评论(0)  编辑  收藏 所属分类: .Net

只有注册用户登录后才能发表评论。


网站导航: