Local Report. GetTotalPages() always return 0

661 Views Asked by At

I have problem with Microsoft.Reporting.WinForms.LocalReport. Method GetTotalPages() always returns zero even after rendering and saving file. Report generated and saved correctly. Help, please.

foreach (DataSet.PersonsRow person in dataSet.Persons.Rows)
{ 

DataSet.PersonsDataTable persons = new DataSet.PersonsDataTable(); 
persons.ImportRow(person); ReportViewer rv = new ReportViewer(); 
string mimeType, encoding, fnameExtension; 
string[] streamids; Warning[] warnings;
rv.ProcessingMode = ProcessingMode.Local; 
rv.LocalReport.ReportPath = "ReportTemplates\\report.rdlc";
rv.LocalReport.SetParameters(new ReportParameter("Parameter", Settings.Parameter.ToString()));
rv.LocalReport.DataSources.Add(new ReportDataSource(dataSet.persons.TableName, (DataTable)persons)); 
rv.LocalReport.DataSources.Add(new ReportDataSource(dataSet.Profile.TableName, (DataTable)dataSet.Profile));
rv.LocalReport.DataSources.Add(new ReportDataSource(dataSet.Places.TableName, dataSet.Equipment.Where(tc => tc.PersonID == person.PersonID)));
byte[] bytes = rv.LocalReport.Render(OutputTypeStr, "<DeviceInfo><SimplePageHeaders>True</SimplePageHeaders></DeviceInfo>", out mimeType, out encoding, out fnameExtension, out streamids, out warnings);

int pagesCount = rv.LocalReport.GetTotalPages(); // pagesCount equal zero 
using (FileStream fs = new FileStream(filename, FileMode.Create)) 
{
    fs.Write(bytes, 0, bytes.Length);
    fs.Close(); 
    pagesCount = rv.LocalReport.GetTotalPages(); // pagesCount also equal zero 
} 

}   
1

There are 1 best solutions below

1
On

I'd like point out that you are not using:

Microsoft.Reporting.WinForms.LocalReport.GetTotalPages(); 

but

Microsoft.Reporting.WinForms.ReportViewer.LocalReport.GetTotalPages(); 

Why do you create LocalReport lr if don't use it?

Hope this helps.