C#获取Microsoft ReportViewer以加载XDocument内容

时间:2012-01-24 12:21:04

标签: c# visual-studio visual-studio-2010 report

我有一个Xdocument对象,其中填充了xml(报告-rdl的定义)。我想将此XDocument的内容提供给报表查看器。

this.reportViewer1.LocalReport.LoadReportDefinition(); 

LoadReportDefinition似乎只接受TextReader或FileStream参数....但我的报表定义是在我的XDocument中加载的?如何流式传输XDocument的内容?

1 个答案:

答案 0 :(得分:3)

您可以使用StringReader类,如下所示:

using (var textReader = new StringReader(xDocument.ToString()))
{
  this.reportViewer1.LocalReport.LoadReportDefinition(textReader);
}

或者使用Stream

using (var stream = new MemoryStream()) 
{
  xDocument.Save(stream);
  stream.Position = 0;
  this.reportViewer1.LocalReport.LoadReportDefinition(stream);
}