2012-01-24 26 views
2

我有一個Xmlocument對象,它填充了xml(報告-rdl的定義)。我想將這個XDocument的內容提供給報表查看器。C#獲取Microsoft ReportViewer加載XDocument內容

this.reportViewer1.LocalReport.LoadReportDefinition(); 

LoadReportDefinition似乎只採取任何的TextReader或參數的FileStream ....但我的報表定義我的XDocument中加載?如何流式傳輸我的XDocument的內容?

回答

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); 
}