opening a file in the browser instead of downloading it

◇◆丶佛笑我妖孽 提交于 2019-12-14 03:49:33

问题


Im using ssrs through a reports server to generate a resultStream byte array using ReportExecutionService.Render() which I am currently serving to the user with the following code. Is there a way I can use this same byte array to automatically open the report in a new browser window instead of going to the save/open dialog?

   public void RenderReport (byte[] reportDigits, ReportItem reportItem)
   {
      HttpResponse response = HttpContext.Current.Response;
      response.Clear();
      response.ContentType = reportItem.ReportMimeType;
      response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", reportItem.ExportName));
      response.OutputStream.Write(reportDigits, 0, reportDigits.Length);
      response.End();
   }

In the past I have used a separate ReportViewer.aspx page that I would open first then display the report but would like to do it all in code behind if that is possible.

Thanks


回答1:


It's this line:

response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", reportItem.ExportName));

Thats causing it to be downloaded. Comment out that line, and as long as the browser can handle the mime type, it will render in the browser window.




回答2:


Simply change the Header that you are adding to something other than an attachement. Make it the format of your data--and hopefully the browser will recognize it.



来源:https://stackoverflow.com/questions/3513961/opening-a-file-in-the-browser-instead-of-downloading-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!