のReportPathプロパティを設定しようと埋め込まれていない場合、私はあなたに似たような状況を持っている私は、レコード生成できるサービスを持っていました。 eaローカルレポートをPDF、電子メールなどに生成することができます。しかし、ReportViewer.LocalReportは読み取り専用のプロパティなので、レポートを作成するためのコードを複製するか、LocalReportからReportViewerに値をコピーする必要があります.LocalReport。私はどちらかのオプションのファンではありません。何かがコピーされない(サブレポートイベント)か、コードの重複があるためです。
私は、ReportViewerでLocalReportをリフレクションして設定する次の拡張を思いついた。私はこれを十分にテストしておらず、悪い考えかもしれません!しかし、それは私が現在取り組んでいるプロジェクトのために働くようです。 ReportViewerがローカルレポートを追加して初期化するかどうかはわかりません。
私はあなたの責任においてこのエンフォースを使用することはできません - わかりやすい説明はしないでください
LocalReport localReport = reportService.GenerateCurrentOrdersReport(....);
reportViewer.SetLocalReport(localReport);
:THIS
public static class ReportViewerExtensions
{
public static void SetLocalReport(this ReportViewer reportViewer, LocalReport report)
{
var currentReportProperty = reportViewer.GetType().GetProperty("CurrentReport", BindingFlags.NonPublic | BindingFlags.Instance);
if (currentReportProperty != null)
{
var currentReport = currentReportProperty.GetValue(reportViewer, null);
var localReportField = currentReport.GetType().GetField("m_localReport", BindingFlags.NonPublic | BindingFlags.Instance);
if (localReportField != null)
{
localReportField.SetValue(currentReport, report);
}
}
reportViewer.RefreshReport();
}
}
使い方をDO