Documente Academic
Documente Profesional
Documente Cultură
without Preview
Other Versions
This walkthrough shows how to programmatically print a report without viewing it, using the LocalReport object and
the CreateStreamCallback callback function.
Prerequisites
You must have access to the sample report and data source. For more information, see Sample Data and Report for Print
Walkthrough.
5. In the Location box, enter the directory in which you want to save your project, or click Browse to navigate to it.
Add references
3. Click OK.
1. From the Project menu, select Add Existing Item. The Add Existing Itemdialog box will appear.
2. Navigate to the folder where you saved report.rdlc and data.xml. Select both files.
3. Click Add. The two files appear in Solution Explorer as part of the project.
Add the code
1. The Program code file should already be open for editing. If it is not, double-click on
the Program.cs or Module1.vb file in the Solution Explorer window.
2. Replace existing code in the Program file with the following code of your programming language choice.
Note
If your there is not a printer named Microsoft XPS Document Writer installed on your machine,
change the bolded code to a named printer on your machine.
C#
using System;
using System.IO;
using System.Data;
using System.Text;
using System.Drawing.Imaging;
using System.Drawing.Printing;
using System.Collections.Generic;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
// Prepare for the next page. Make sure we haven't hit the end.
m_currentPageIndex++;
ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
}
VB
Imports System
Imports System.IO
Imports System.Data
Imports System.Text
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Drawing.Printing
Imports System.Collections.Generic
Imports System.Windows.Forms
Imports Microsoft.Reporting.WinForms
' Prepare for the next page. Make sure we haven't hit the end.
m_currentPageIndex += 1
ev.HasMorePages = (m_currentPageIndex < m_streams.Count)
End Sub
1. On the Build menu, click on Build Solution to build the application. As part of the build process, the report is
compiled and any errors found (such as a syntax error in an expression used in the report) are added to the Task List.
The code above will print the report to an .xps file and prompt you for the file location. If you specify the name of a
printing device, it will print the report to that device directly.