2016-11-18 1 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);