Problem with Localreport and MemoryStream

T

Tom

Hello,

I've a problem with Localreports and .Net2005. I wanna print different
reports in the background without reportviewer. One of this reports
has 6 pages but only 4 of them will be print. The reports are filled
with up to 7 datasets.
I only get the 4 pages of the 6 pages report when I'm using
"LocalReport.GetTotalPages(); " If I'm using "LocalReport.Render" I
get the streamIDs (see code) as zero length.
Does someone has an idea how I can get all the pages? And why and when
is "out stream" and why I get a Zero length?

Thanks for your help

tom
private void Export(ReportViewer report)
{
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>EMF</OutputFormat>" +
" <PageWidth>29.7cm</PageWidth>" +
" <PageHeight>21cm</PageHeight>" +
" <MarginTop>0.1in</MarginTop>" +
" <MarginLeft>0.1in</MarginLeft>" +
" <MarginRight>0.1in</MarginRight>" +
" <MarginBottom>0.1in</MarginBottom>" +
" <StartPage>0</StartPage>" +
"</DeviceInfo>";


if (m_streams != null)
{
m_streams = null;
}
m_streams = new List<Stream>();


string encoding;
string mimeType;
string extension;
Warning[] warnings;
string[] streamIDs ; //= null;
Byte[][] pages = null;


//Create Byte array containing the rendered image. of the
1st page.
Byte[] firstPage = report.LocalReport.Render("Image",
deviceInfo, out mimeType, out encoding, out extension, out streamIDs,
out warnings);


m_streams.Add(new MemoryStream(firstPage));


// The total number of pages of the report is 1 + the
streamIDs
// int m_numberOfPages = streamIDs.Length + 1;
m_numberOfPages = report.LocalReport.GetTotalPages();
pages = new Byte[m_numberOfPages][];


// The first page was already rendered
pages[0] = firstPage;


for (int pageIndex = 1; pageIndex < m_numberOfPages;
pageIndex++)
{
// Build device info based on start page
deviceInfo = String.Format(
"<DeviceInfo>" +
" <OutputFormat>EMF</OutputFormat>" +
" <PageWidth>29.7cm</PageWidth>" +
" <PageHeight>21cm</PageHeight>" +
" <MarginTop>0.1in</MarginTop>" +
" <MarginLeft>0.1in</MarginLeft>" +
" <MarginRight>0.1in</MarginRight>" +
" <MarginBottom>0.1in</MarginBottom>" +
" <StartPage>{0}</StartPage>" +
"</DeviceInfo>", pageIndex + 1);


//Render the page to a byte array.
pages[pageIndex] = report.LocalReport.Render("Image",
deviceInfo, out mimeType, out encoding, out extension, out streamIDs,
out warnings);


//create a stream of the page's byte array
m_streams.Add(new MemoryStream(pages[pageIndex]));
//set the position of the stream to 0 to make sure
when the stream is read
//it starts from the beginning.
m_streams[m_streams.Count - 1].Position = 0;
}


m_currentPageIndex = 0;


foreach (Stream stream in m_streams)
stream.Position = 0;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top