{"id":223,"date":"2012-02-15T15:28:50","date_gmt":"2012-02-15T06:28:50","guid":{"rendered":"http:\/\/sorceryforce.net\/WordPress\/?p=223"},"modified":"2022-08-09T22:32:59","modified_gmt":"2022-08-09T13:32:59","slug":"asp-net-mvc-filepathresult-%e3%81%a7%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e8%bf%94%e3%81%99%e3%81%a8-ie8-%e4%bb%a5%e5%89%8d%e3%81%ae%e3%83%96%e3%83%a9%e3%82%a6%e3%82%b6%e3%81%a7%e6%84%8f","status":"publish","type":"post","link":"https:\/\/blog.sorceryforce.net\/?p=223","title":{"rendered":"[ASP.NET MVC] FilePathResult \u3067\u30d5\u30a1\u30a4\u30eb\u3092\u8fd4\u3059\u3068 IE8 \u4ee5\u524d\u306e\u30d6\u30e9\u30a6\u30b6\u3067\u610f\u56f3\u3057\u306a\u3044\u30d5\u30a1\u30a4\u30eb\u540d\u3067\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3055\u308c\u308b"},"content":{"rendered":"<p><!--[CDATA[\n\n<p-->\u30a2\u30af\u30b7\u30e7\u30f3\u30e1\u30bd\u30c3\u30c9\u5185\u3067 File \u30e1\u30bd\u30c3\u30c9 (FilePathResult) \u3092\u4f7f\u7528\u3057\u3066\u30d5\u30a1\u30a4\u30eb\u3092\u8fd4\u3057\u3066\u3044\u308b\u51e6\u7406\u304c\u3042\u3063\u305f\u306e\u3067\u3059\u304c\u3001IE \u3067\u30d5\u30a1\u30a4\u30eb\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u305f\u969b\u306b\u3059\u3079\u3066\u540c\u3058\u30d5\u30a1\u30a4\u30eb\u540d\u3067\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3055\u308c\u3066\u3057\u307e\u3046\u3068\u3044\u3046\u5831\u544a\u3092\u53d7\u3051\u305f\u306e\u3067\u8abf\u3079\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u7406\u7531\u306b\u3064\u3044\u3066\u306f\u300c<a href=\"http:\/\/devadjust.exblog.jp\/11395131\/\">ASP.NET MVC2 \u306e FileContentResult \u3067\u65e5\u672c\u8a9e\u30d5\u30a1\u30a4\u30eb\u540d\u3067\u8fd4\u3059\u3068 IE \u3067\u65e5\u672c\u8a9e\u30d5\u30a1\u30a4\u30eb\u540d\u306b\u306a\u3089\u306a\u3044<\/a>\u300d\u306e\u30ea\u30f3\u30af\u5148\u3092\u898b\u3066\u3082\u3089\u3048\u308c\u3070\u305d\u306e\u307e\u307e\u306a\u306e\u3067\u3059\u304c\u3001IE8 \u4ee5\u524d\u3060\u3068\u3001File \u30e1\u30bd\u30c3\u30c9\u306e fileDownloadName \u5f15\u6570\u306b\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u6307\u5b9a\u3057\u3066\u3082\u30a2\u30af\u30b7\u30e7\u30f3\u540d\u3067\u30d5\u30a1\u30a4\u30eb\u540d\u304c\u8fd4\u3063\u3066\u3057\u307e\u3046\u307f\u305f\u3044\u3067\u3059\u3002<\/p>\n<p>\u5bfe\u5fdc\u7b56\u306f\u3084\u306f\u308a\u30ea\u30f3\u30af\u5148\u306e\u3088\u3046\u306b\u30af\u30e9\u30b9\u3092\u6d3e\u751f\u3055\u305b\u3066\u5bfe\u5fdc\u3067\u304d\u307e\u3057\u305f\u3002\u79c1\u306e\u5834\u5408\u306f\u30ed\u30fc\u30ab\u30eb\u306b\u3042\u308b\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3055\u305b\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u305f\u306e\u3067\u300cFilePathResult\u300d\u30af\u30e9\u30b9\u304b\u3089\u6d3e\u751f\u3055\u305b\u3066\u3044\u307e\u3059\u3002\u30b3\u30fc\u30c9\u306f\u4e0b\u306e\u3088\u3046\u306a\u611f\u3058\u3067\u3059\u3002(\u30af\u30e9\u30b9\u540d\u306f\u9069\u5f53\u306a\u306e\u3067\u6c17\u306b\u3057\u306a\u3044\u3067\u304f\u3060\u3055\u3044)<\/p>\n<pre class=\"diagram\"><code>\/\/\/ &lt;summary&gt;<summary>\n\/\/\/ IE 8 \u4ee5\u524d\u3067\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u6b63\u5e38\u306b\u8fd4\u305b\u306a\u3044\u4e0d\u5177\u5408\u306b\u5bfe\u5fdc\u3057\u305f FilePathResult\u3002\n\/\/\/ &lt;\/summary&gt;<\/summary>\npublic class FilePathResultEx : FilePathResult\n{\n    public FilePathResultEx(string fileName,\n                            string contentType,\n                            string fileDownloadName)\n        : base(fileName, contentType)\n    {\n        base.FileDownloadName = fileDownloadName;\n    }\n    public override void ExecuteResult(ControllerContext context)\n    {\n        \/\/ IE \u4ee5\u5916\u3067\u306f\u57fa\u5e95\u306e\u51e6\u7406\u306b\u4efb\u305b\u308b(RFC2231)\n        if (context.HttpContext.Request.Browser.Browser != \"IE\")\n            base.ExecuteResult(context);\n        else\n        {\n            var fileName = this.FileDownloadName;\n            fileName = HttpUtility.UrlEncode(fileName).Replace(\"+\", \"%20\");\n            var response = context.HttpContext.Response;\n            response.ContentType = this.ContentType;\n            response.AddHeader(\"content-disposition\", \"attachment; filename=\" + fileName);\n            this.WriteFile(response);\n        }\n    }\n}\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u30a2\u30af\u30b7\u30e7\u30f3\u30e1\u30bd\u30c3\u30c9\u3067\u306f\u4e0b\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u3066\u8fd4\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"diagram\"><code>string localFilePath = @\"&lt;\u30ed\u30fc\u30ab\u30eb\u306e\u30d5\u30a1\u30a4\u30eb\u30d1\u30b9&gt;\";\nstring contentType = \"&lt;\u30d5\u30a1\u30a4\u30eb\u306e\u30b3\u30f3\u30c6\u30f3\u30c4\u30bf\u30a4\u30d7&gt;\";\nstring downloadFileName = \"&lt;\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3055\u305b\u308b\u30d5\u30a1\u30a4\u30eb\u540d&gt;\";\n\/\/ \u4e0b\u306e\u30e1\u30bd\u30c3\u30c9\u306f\u3084\u3081\u308b\n\/\/return File(localFilePath, contentType, downloadFileName);\n\/\/ \u30d8\u30c3\u30c0\u30fc\u3092\u5909\u66f4\u3057\u305f\u30ec\u30b9\u30dd\u30f3\u30b9\u3092\u8fd4\u3059 FilePathResul \u62e1\u5f35\u30af\u30e9\u30b9\u3067\u5bfe\u5fdc\nreturn new FilePathResultEx(localFilePath, contentType, FileName);\n<\/code><\/pre>\n<p>]]&gt;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\t\t\t\t<![CDATA[]]>\t\t<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[75,148,150,151,175,265,648],"class_list":["post-223","post","type-post","status-publish","format-standard","hentry","category-6","tag-asp-net-mvc","tag-file","tag-filecontentresult","tag-filepathresult","tag-ie","tag-rfc","tag-648"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.sorceryforce.net\/index.php?rest_route=\/wp\/v2\/posts\/223"}],"collection":[{"href":"https:\/\/blog.sorceryforce.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.sorceryforce.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.sorceryforce.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.sorceryforce.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=223"}],"version-history":[{"count":1,"href":"https:\/\/blog.sorceryforce.net\/index.php?rest_route=\/wp\/v2\/posts\/223\/revisions"}],"predecessor-version":[{"id":2347,"href":"https:\/\/blog.sorceryforce.net\/index.php?rest_route=\/wp\/v2\/posts\/223\/revisions\/2347"}],"wp:attachment":[{"href":"https:\/\/blog.sorceryforce.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.sorceryforce.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.sorceryforce.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}