我正在开发网络应用程序,在我的应用程序中我必须打印rdlc而不预览。我的代码如下:
LocalReport report = new LocalReport();
report.ReportEmbeddedResource = "TCESS.ESales.CommonLayer.Reports.HandlingBillReport.rdlc";
report.ReportPath="TCESS.ESales.CommonLayer.Reports.HandlingBillReport.rdlc";
SettlementOfAccountsDTO objSettlementOfAccountsDTO = ESalesUnityContainer.Container.Resolve<ISettlementOfAccountsService>().GetSettlementOfAccountsByAccId(32);
if (objSettlementOfAccountsDTO.Account_Id > 0)
{
SetReportParametersForBill(objSettlementOfAccountsDTO, AccountReportViewer, report);
}
Export(report);
m_currentPageIndex = 0;
Print();
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;
}
private void Export(LocalReport report)
{
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>";
Warning[] warnings;
m_streams = new List<Stream>();
report.Render("Image", deviceInfo, CreateStream, out warnings);
foreach (Stream stream in m_streams)
stream.Position = 0;
}
private void PrintPage(object sender, PrintPageEventArgs ev)
{
Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]);
ev.Graphics.DrawImage(pageImage, 0, 0);
m_currentPageIndex++;
ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
}
private void Print()
{
const string printerName = "\\\\193.168.0.20\\Printer_Q3";
if (m_streams == null || m_streams.Count == 0)
return;
PrintDocument printDoc = new PrintDocument();
printDoc.PrinterSettings.PrinterName = printerName;
if (!printDoc.PrinterSettings.IsValid)
{
string msg = String.Format("Can't find printer \"{0}\".", printerName);
Console.WriteLine(msg);
return;
}
int i=0;
foreach (Stream stream in m_streams)
{
Metafile pageImage = new Metafile(stream);
pageImage.Save(Server.MapPath("~/Images/"+i.ToString()+".jpg"));
i++;
}
//printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
//printDoc.Print();
}
我收到错误“报告的报告定义''尚未指定” 在线
report.Render("Image", deviceInfo, CreateStream, out warnings);
答案 0 :(得分:3)
我在实例化要导出的报告时遇到了这个问题,并且必须像这样设置此属性:
wrvReport.LocalReport.ReportEmbeddedResource = "CommonLayer.Reports.SalesByPrice.rdlc";
我看到的差异是.LocalReport
是设置嵌入资源的子属性。
答案 1 :(得分:1)
嵌入式报表资源是已经存在的报表定义 存储为调用程序集中的资源。
如果已设置ReportPath属性,则为ReportEmbeddedResource 属性被忽略。
因此,设置EmbeddedResource属性实际上什么都不做,并且ReportPath也失败了,因为它需要物理文件系统路径。
答案 2 :(得分:1)
我遇到了同样的问题。我通过设置“复制到输出目录=复制如果更新”来解决它。欢呼声。
答案 3 :(得分:0)
我也有同样的问题,这意味着您的代码没有找到rdlc文件,您需要使用report.ReportEmbeddedResource
或report.ReportPath
。在我看来,您的代码只需要使用report.ReportEmbeddedResource
,另一个选项是位于您的电脑或网络文件系统中特定位置的rdlc