In Windows Forms applications, you can print reports without previewing them using the Print method that is implemented as an extension method for the SectionDocument and PageDocument classes. Because it is an extension of the PrintExtension class, Print is not listed as a method on either of the document classes. You can find it in the GrapeCity.ActiveReports.Viewer.Win.v10 assembly under the GrapeCity.ActiveReports namespace. There are two ways to call this extended Print method. You can call it on the document object, or call it on the PrintExtension object and pass in the document. I've provided both ways in the code samples below, and commented out one of them. Also, you can see that one of them uses a Section report and the other uses a Page report.
' Visual Basic
Imports GrapeCity.ActiveReports
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim sectionReport As New GrapeCity.ActiveReports.SectionReport()
Dim xtr As New System.Xml.XmlTextReader("..\\..\\PurchaseOrder.rpx")
sectionReport.LoadLayout(xtr)
xtr.Close()
sectionReport.Run()
Dim sectionDocument = sectionReport.Document
' sectionDocument.Print ' OR
PrintExtension.Print(sectionDocument, True, True)
End Sub
End Class
// C#
using System;
using System.Windows.Forms;
using GrapeCity.ActiveReports;
namespace winFormsPrintNoViewer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string file_name = @"..\\..\\Catalog.rdlx";
GrapeCity.ActiveReports.PageReport pageReport = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(file_name));
GrapeCity.ActiveReports.Document.PageDocument pageDocument = new GrapeCity.ActiveReports.Document.PageDocument(pageReport);
// pageDocument.Print(); // OR
PrintExtension.Print(pageDocument, true, true);
}
}
}
If you see error messages like these, the tips below will help.
VB.NET
C#
To use the Print method, add a reference to the GrapeCity.ActiveReports.Viewer.Win.v10 assembly in your application.
To enable the Print method, you also need to explicitly import the GrapeCity.ActiveReports namespace. Add code like the following at the beginning of the code file that calls the Print method.
'VB.NET
Imports GrapeCity.ActiveReports
//C#
using GrapeCity.ActiveReports;
Important: When you upgrade old ActiveReports projects, especially those created using ActiveReports version 6 or lower, the reference and code to import isn't added automatically with the ActiveReports 10 Upgrade tool. You can find more information on printing in Print Methods In ActiveReports.