views:

260

answers:

1

SQL Server 2008 Reporting Services allow to open report in PDF with following URL access:

http://localhost:8080/reportserver?/MyReports/Report1&rs:Command=Render&rs:Format=PDF

but the PDF will be open in a new browser window. How to set proper parameter and open it in current browser window?

A: 

Ok cool, we have something to start with. It was tricky to work out how to do this (it took a reasonable number of hours), and i'm not at liberty to give you the exact code (as it belongs to the people i wrote it for), but i can give you the method for doing it. With this method you should be able to nicely host the aspx page inside a silverlight control, although you may have to think about the physical size of your rendered report it may be a little tight on space when hosted like that.

  • in your aspx page, create an HttpWebRequest, the url should point to the appropriate reports folder in the SSRS installation
  • create the querystring which contains the report parameters, convert it to a byte[] using Encoding.UTF8.GetBytes(parameterString)
  • write that byte array to the RequestStream of the HttpWebRequest you created
  • do a request.GetResponse(), assign it's output to a new HttpWebResponse object (let's call it the ssrsResponse)
  • get the response object of the current page (let's call it currentResponse)
  • set the content type of currentResponse to Application/PDF
  • add the Content-Disposition header to currentResponse, set its value to inline;filename=[insert filename here]
  • read the response stream from ssrsResponse and write it to currentResponse (this is just an exercise in transferring the contents of one stream to another)
  • call currentResponse.End()
slugster
Thank you. So I want to create a http handler at server side only for reporting service url, say ReportingService.ashx. The all I need to do is to implement above guide in public void ProcessRequest(HttpContext context) {...}. But I am not familiar with httphandler. Could you give me the demo code for your guide?
KentZhou
No, there is no HttpHandler required. This is all done within a single aspx page.
slugster
Thank you, slugster. I have created a httphandler to implement your suggestion. It works fine in IE, but not in FF, it still shows the download popup and then display the pdf in another window(pdf reader). Not sure why. any idea?
KentZhou

related questions