我试图在不显示 Microsoft Report Viewer 的情况下直接打印 RDLC 文件,我遵循了MSDN 的示例,但现在,每次我调用 LocalReport 类实例的“Render”方法时,它都会抛出“一个或多个参数需要运行报告尚未指定。” 例外。
谁能告诉我我错过了哪个参数?或者我如何才能找到有关此异常的更多详细信息?
LocalReport report = new LocalReport();
report.ReportPath = System.Windows.Forms.Application.StartupPath + "\\" + rdlcFileName;
report.EnableExternalImages = true;
ReportParameter[] reportParams = new ReportParameter[]
{
new ReportParameter("LogoAddress", settings.LogoFileName),
new ReportParameter("FooterValue", settings.InvoicesFooter)
};
report.SetParameters(reportParams);
report.DataSources.Add(new ReportDataSource("Invoice", new PrintableInvoice[] { invoice }));
report.DataSources.Add(new ReportDataSource("InvoiceItem", invoiceItems));
Warning[] warnings;
try
{
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>EMF</OutputFormat>" +
" <PageWidth>8.5in</PageWidth>" +
" <PageHeight>11in</PageHeight>" +
" <MarginTop>0.25in</MarginTop>" +
" <MarginLeft>0.25in</MarginLeft>" +
" <MarginRight>0.25in</MarginRight>" +
" <MarginBottom>0.25in</MarginBottom>" +
"</DeviceInfo>";
m_streams = new List<Stream>();
report.Render("Image", deviceInfo, _CreateStream, out warnings);
foreach( Stream stream in m_streams )
stream.Position = 0;
}
catch( Exception ex )
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
_CreateStream 是:
private Stream _CreateStream(string name, string fileNameExtension, Encoding encoding, string mimeType, bool willSeek)
{
Stream stream = new FileStream(name + "." + fileNameExtension, FileMode.Create);
m_streams.Add(stream);
return stream;
}