2014-12-05 3 views
0

아래의 방법을 보고서 컨트롤러에서 사용합니다. 그것은 성공적으로 내 데이터베이스의 varBinary (MAX) 필드에 할당 한 파일 내용을 반환합니다. 내 문제는,이 코드를 실행하면 브라우저가 사용자에게 SAVE 또는 OPEN 파일을 표시하도록합니다. 나는 이것을 막기를 원한다.파일을 저장하라는 메시지가 나타나지 않게하십시오.

바이너리 데이터를 호출 컨트롤러 메서드로 반환하고 결과를 클라이언트 브라우저로 푸시하지 않는 방법은 무엇입니까?

private FileContentResult RenderReportFile(LocalReport localReport, List<ReportDataSource> listDS, string sFilename, string sReportType, bool bLandscape) 
{ 
    string sHeight = "11"; 
    string sWidth = "8.5"; 

    if (bLandscape) 
    { sWidth = sHeight; sHeight = "8.5"; } 

    foreach (ReportDataSource ds in listDS) 
    { 
     localReport.DataSources.Add(ds); 
    } 

    HttpContextBase imageDirectoryPath = HttpContext; 

    string reportType = sReportType; 
    string mimeType; 
    string encoding; 
    string fileNameExtension; 

    //The DeviceInfo settings should be changed based on the reportType 
    string deviceInfo = 
     "<DeviceInfo>" + 
     " <OutputFormat>" + sReportType + "</OutputFormat>" + 
     " <PageWidth>" + sWidth + "in</PageWidth>" + 
     " <PageHeight>" + sHeight + "in</PageHeight>" + 
     " <MarginTop>0.5in</MarginTop>" + 
     " <MarginLeft>0.5in</MarginLeft>" + 
     " <MarginRight>0.5in</MarginRight>" + 
     " <MarginBottom>0.5in</MarginBottom>" + 
     "</DeviceInfo>"; 

    Warning[] warnings; 
    string[] streams; 
    byte[] renderedBytes; 

    //Render 
    renderedBytes = localReport.Render(
     reportType, 
     deviceInfo, 
     out mimeType, 
     out encoding, 
     out fileNameExtension, 
     out streams, 
     out warnings); 


    //Write to the outputstream 
    //Set content-disposition to "attachment" so that user is prompted to take an action 
    //on the file (open or save) 

    Response.Clear(); 
    Response.ContentType = mimeType; 
    Response.AddHeader("content-disposition", "attachment; filename=" + sFilename + "." + fileNameExtension); 
    Response.BinaryWrite(renderedBytes); 
    Response.End(); 
    return File(renderedBytes, "application/pdf", sFilename + "." + fileNameExtension); 
} 
+0

콘텐츠를 사용하지 마십시오. –

+1

왜 클라이언트에 푸시하지 않으시겠습니까? 그걸로 무엇을하고 싶니? –

+0

'Response '를 직접 조작하는 이유는 무엇입니까? –

답변

1

이 코드는 클라이언트에 문서를 전송하는 책임이있다 :

Response.Clear(); 
Response.ContentType = mimeType; 
Response.AddHeader("content-disposition", "attachment; filename=" + sFilename + "." + fileNameExtension); 
Response.BinaryWrite(renderedBytes); 
Response.End(); 

그것을 제거하고 저장하거나 개방에 대한 사용자 메시지가 표시되지 않습니다.

관련 문제