レポートのパブリッシュは、PDF または XPS ファイルを書き出すことと同義語です。レポートを作成およびデザインしたら、Report オブジェクトから Publish メソッドを使用して、パブリッシュすることができます。Publish メソッドには 2 つのオーバーロードがあります。
以下のコードは、現在のユーザーのマイ ドキュメント フォルダー内にあるレポート(Report オブジェクトが「レポート」として定義されることを前提とします)を PDF ファイルとしてパブリッシュします。レポートがパブリッシュされたら、System.Diagnostics 名前空間から Process.Start メソッドを使用して、新しい PDF ファイルを開くことができます。ボタン、ツールバー、メニュー、またはその他の任意のクリック可能な UI 要素から Start メソッドを呼び出すことも可能です。
注: プロセスを開始する前にエンド ユーザーのシステムに Adobe Acrobat Reader がインストールされていることを確認してください。Acrobat Reader がインストールされていない場合には、トライ/キャッチ ブロックを使用して、例外をキャッチするといいでしょう。また、XPS ドキュメントを表示したい場合には、エンド ユーザーのシステムに .NET Framework 3.0 がインストールされている必要があります。
C# の場合:
// define a string that contains the path to
// the current user's My Documents folder.
string myDocuments =
System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
// Publish the report to the current user's
// My Documents folder with the name of Report.pdf.
// The FileFormat enum can be used to publish the report
// as an XPS or plain text file as well. Remember to
// change the file extension if you change the file format.
report.Publish(myDocuments + "Report.pdf", FileFormat.PDF);
// The Process.Start method runs the specified file
// using the application registered to run that file.
System.Diagnostics.Process.Start(myDocuments + "Report.pdf");
オンラインで表示: GitHub