Hi, in one of my projects I use the following code to obtain one stream per page. Unfortunately I don't use VB.NET, but you should be able to translate this from C# to VB. Note: This works on SSRS2005 - I'm not sure it also works for SSRS2008! Also, I'm using the code to directly print the report without having to use the report viewer, so I'm creating an EMF device info - you might have to change this.
This base code was found somewhere on the Web after Googling for hours - I'd like to credit the author, but I didn't bookmark the link - sorry.
CultureInfo us = new CultureInfo("en-US");
string deviceInfo = String.Format(
"<DeviceInfo>" +
" <OutputFormat>EMF</OutputFormat>" +
" <PageWidth>{0}cm</PageWidth>" +
" <PageHeight>{1}cm</PageHeight>" +
" <MarginTop>{2}cm</MarginTop>" +
" <MarginLeft>{3}cm</MarginLeft>" +
" <MarginRight>{4}cm</MarginRight>" +
" <MarginBottom>{5}cm</MarginBottom>" +
"</DeviceInfo>",
Math.Round(m_pageSize.Width, 2).ToString(us),
Math.Round(m_pageSize.Height, 2).ToString(us),
Math.Round(m_marginTop, 2).ToString(us),
Math.Round(m_marginLeft, 2).ToString(us),
Math.Round(m_marginRight, 2).ToString(us),
Math.Round(m_marginBottom, 2).ToString(us));
m_reportStreams = new List<Stream>();
try
{
// Tell SSRS to store one stream per page on server
NameValueCollection urlAccessParameters = new NameValueCollection();
urlAccessParameters.Add("rs:PersistStreams", "True");
// Render first page
Stream s = viewer.ServerReport.Render("IMAGE", deviceInfo, urlAccessParameters, out mime, out extension);
m_reportStreams.Add(s);
// Loop to get other streams
urlAccessParameters.Remove("rs:PersistStreams");
urlAccessParameters.Add("rs:GetNextStream", "True");
do
{
s = viewer.ServerReport.Render("IMAGE", deviceInfo, urlAccessParameters, out mime, out extension);
if (s.Length != 0) m_reportStreams.Add(s);
}
while (s.Length > 0);
// Now there's one stream per page - do stuff with it
}
finally
{
foreach (Stream s in m_reportStreams)
{
s.Close();
s.Dispose();
}
m_reportStreams = null;
}
EDIT
Forgot to mention that viewer
is a programmatically created instance of the ReportViewer
control initialized to render the report that you're trying to print/save.