我对 Microsoft.Reporting.WinForms.LocalReport 有疑问。即使在渲染和保存文件之后,方法 GetTotalPages() 也始终返回零。报告生成并正确保存。请帮忙。
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
}
}