Printing a Server Report without Preview only printing the first page

Printing a report without preview programmatically in C#, only printing the first page of the report if there are more than one pages.

1. From this example with local report without preview:
2. We can print a report without preview, but it only prints the first page.
3. I’m using Server Report here as an example.


Instead of using this code to get the stream:

List<Stream> m_streams = new List<Stream>();
byte[] s = report.Render(“Image”, deviceInfo, out sMimeType, out sEncoding, out sExtension, out sStreamIds, out warnings);

Stream fs = new MemoryStream();
fs.Write(s, 0, s.Length);

We need to split it up into one stream per page:

List<Stream> m_streams = new List<Stream>();
//Split the stream per page
NameValueCollection urlAccessParameters = new NameValueCollection();
urlAccessParameters.Add(“rs:PersistStreams”, “True”);

//Get the first page
Stream s = _reportViewer.ServerReport.Render(“IMAGE”, deviceInfo, urlAccessParameters, out sMimeType, out sExtension);
//Loop until all pages finish
urlAccessParameters.Add(“rs:GetNextStream”, “True”);
s = _reportViewer.ServerReport.Render(“IMAGE”, deviceInfo, urlAccessParameters, out sMimeType, out sExtension);
if (s.Length != 0) m_streams.Add(s);
while (s.Length > 0);

Then you will get the result with one stream per page.

Now you can replace the code to print reports with multiple pages with the Microsoft example.