メインメニューを開く

FileContentResult クラス (System.Web.Mvc)

2012年4月18日 (水) 11:46時点におけるimported>Administratorによる版 (FileContentResultFileContentResult クラス (System.Web.Mvc)へ移動)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)

FileContentResultクラスとは、ASP.NET MVCアクション・メソッドの戻り値(ActionResultおよびその派生クラス)として、byte配列の内容をバイナリデータとしてそのまま送信するFileResultクラスを継承したクラスである。

目次

使用例編集

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

    public class HomeController : Controller
    {
        public ActionResult DownloadCsv()
        {
            this.HttpContext.Response.AddHeader(
                "Content-Disposition", 
                "attachment; filename=hello.csv");

            byte[] data = Encoding.UTF8.GetBytes("hello, world");
            return new FileContentResult(data, "text/csv");
        }
    }

関連項目編集

参考文献編集

外部リンク編集