2016-11-18 5 views
1

サーバーにダウンロードしてブラウザに返信したいPDFファイルがありますが、代わりに画面に読み込まれます。PDFをダウンロードして画面に表示しない

public ActionResult BillOfMaterials(Model model) 
{ 
    .... 
    return File(@"C:\...(file path)...\result.pdf", "application /pdf"); 
} 

私はそれ実際にちょうどダウンロードし、ブラウザで開かないように何をする必要があります:これは私がやっているのですか?

ありがとうございます!

+3

これはあなたが探しているものですか? https://stackoverflow.com/questions/5826649/returning-a-file-to-view-download-in-asp-net-mvc?rq=1 – ElectricRouge

+1

おそらくこれもあなたを助けるかもしれません:http://stackoverflow.com/questions/8590543/force-browser-to-download-pdf-document-of-opening-it –

答えて

0

これはそれでした。

  string filepath = @"C:\docs\result.pdf"; 
      byte[] filedata = System.IO.File.ReadAllBytes(filepath); 
      string contentType = System.Web.MimeMapping.GetMimeMapping(filepath); 

      var cd = new System.Net.Mime.ContentDisposition 
      { 
       FileName = "result.pdf", 
       Inline = false, 
      }; 

      Response.AppendHeader("Content-Disposition", cd.ToString()); 

      return File(filedata, contentType); 
関連する問題