tag:blogger.com,1999:blog-59245886806838174252024-03-09T05:49:04.709+05:30Print SSRS report ProgramaticallyThis post Explains how to print SSRS report using SSRS ReportExecutionService (ReportExecution2005.asmx which is installed along with SQL server 2008 or SQL Server 2008 R2)......
i.e How to print SSRS report programatically without displaying/previewing it.Narendrahttp://www.blogger.com/profile/13112817201598525701noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-5924588680683817425.post-61032196608395448502011-09-24T21:37:00.001+05:302011-09-24T21:40:48.571+05:30Create new SSRS Report using ReportingService.CreateCatalogItem() method<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="color: black; font-family: "Arial", "sans-serif"; font-size: 10pt; line-height: 115%;">This post explains about programmatically creating a new SSRS report using Reporting Services Web service.</span></div>
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="color: black; font-family: "Arial", "sans-serif"; font-size: 10pt; line-height: 115%;">PreRequisite : You must have SSRS(SQL Server Reporting Services) installed so that you can use Reporting web services provided by SSRS.</span></div>
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<br /></div>
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="color: black; font-family: "Arial", "sans-serif"; font-size: 10pt; line-height: 115%;">Step 1: <strong><span style="font-family: "Arial", "sans-serif";">Add Reference to Web </span></strong></span><strong><span style="color: black; font-family: "inherit", "serif"; font-size: 10pt; line-height: 115%; mso-bidi-font-family: Arial;">Service</span></strong><strong><span style="color: black; font-family: "Arial", "sans-serif"; font-size: 10pt; line-height: 115%;">()</span></strong><span style="color: black; font-family: "Arial", "sans-serif"; font-size: 10pt; line-height: 115%;"><br /></span><span style="color: black; font-family: "Verdana", "sans-serif"; font-size: 10pt; line-height: 115%; mso-bidi-font-family: Arial;">The first thing you need to do is add a Web reference to the Reporting Services Web service in your development project that points to your report server. </span><span style="color: black; font-family: "Arial", "sans-serif"; font-size: 10pt; line-height: 115%;"><br /></span><span style="color: black; font-family: "Verdana", "sans-serif"; font-size: 10pt; line-height: 115%; mso-bidi-font-family: Arial;">To do so right-click on your project in Visual Studio and choose <strong><span style="font-family: "Verdana", "sans-serif"; mso-bidi-font-family: Arial;">Add Service reference...</span></strong></span><span style="color: black; font-family: "Arial", "sans-serif"; font-size: 10pt; line-height: 115%;"> .Then Click on <strong><span style="font-family: "Arial", "sans-serif";">Advanced</span></strong> and then <strong><span style="font-family: "Arial", "sans-serif";">"Add Web Reference.."</span></strong> as shown in below image..</span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-rd9jHAI241s/Tn36_7B-G1I/AAAAAAAAACw/a0QrcRyvVOE/s1600/Add_Service_Reference.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" hca="true" src="http://1.bp.blogspot.com/-rd9jHAI241s/Tn36_7B-G1I/AAAAAAAAACw/a0QrcRyvVOE/s1600/Add_Service_Reference.jpg" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<span style="color: black; font-family: "Verdana", "sans-serif"; font-size: 10pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";"></span><br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: black; font-family: "Verdana", "sans-serif"; font-size: 10pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";">Provide report server URL (in my case <a href="http://localhost/reportserver/ReportExecution2005.asmx"><span style="mso-bidi-font-size: 11.0pt;"><span style="color: #1282f3;">http://localhost/reportserver/</span></span></a></span><span style="color: #1282f3; font-family: "Verdana", "sans-serif"; font-size: 10pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";">ReportService2010.asmx</span><span style="color: black; font-family: "Verdana", "sans-serif"; font-size: 10pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";">). If you have a remote report server, simply change the URL of the Web reference. The end point for any Reporting Services Web service is </span><span style="color: #1282f3; font-family: "Verdana", "sans-serif"; font-size: 10pt; mso-bidi-font-family: Arial; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: "Times New Roman";"><a href="http://servername/reportserver/ReportService2010.asmx%20"><span style="color: #1282f3;">http://servername/reportserver/ReportService2010.asmx</span></a></span><span style="color: black; font-family: "Verdana", "sans-serif"; font-size: 10pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";">.</span><span style="color: black; font-family: "Arial", "sans-serif"; font-size: 10pt; mso-fareast-font-family: "Times New Roman";"></span></div>
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="color: black; font-family: "Verdana", "sans-serif"; font-size: 10pt; line-height: 115%; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";">Provide service reference name(i provided "ExecutionService" as reference name) and click on Add.</span></div>
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<br /></div>
<span style="color: black; font-family: "Verdana", "sans-serif"; font-size: 10pt; line-height: 115%; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman";"><div class="MsoNormal" style="margin: 0in 0in 10pt;">
<b style="mso-bidi-font-weight: normal;"><span style="font-size: small;"><span style="font-family: Calibri;">Step 2: Using <span style="mso-spacerun: yes;"> </span></span></span></b><b style="mso-bidi-font-weight: normal;"><span style="color: black; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-bidi-font-family: Tahoma; mso-fareast-font-family: "Times New Roman";">ReportingService.CreateCatalogItem method To create new Report</span></b></div>
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="color: black; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-bidi-font-family: Tahoma; mso-fareast-font-family: "Times New Roman";"></span><span style="color: black; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">ReportingService.ReportingService2010 rs</span><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">;</span><span style="color: black; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">rs </span><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">= new </span><span style="color: black; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">ReportingService.ReportingService2010()</span><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">;</span></div>
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;"><span style="color: black; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">rs.Credentials </span><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">= </span><span style="color: black; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">Net.CredentialCache.DefaultNetworkCredentials</span><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">;</span><span style="color: black; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">rs.Url </span><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">= </span><span style="color: grey; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">"http://localhost/ReportServer/ReportService2010.asmx"</span><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">;<br />string </span><span style="color: black; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">_reportPath</span><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">;</span><span style="color: black; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">_reportPath </span><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">= </span><span style="color: grey; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">"/"</span><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">;</span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;"><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;"><span style="color: black; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">Byte[] reportDefinition </span><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">= null;</span></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;"><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;"><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;"><span style="color: black; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">ReportingService.Warning[] warnings </span><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">= null;</span></span></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;"><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;"><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;"><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;"><span style="color: black; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">ReportingService.CatalogItem newCreatedReport </span><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">= </span><span style="color: black; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">rs.CreateCatalogItem(</span><span style="color: grey; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">"Report"</span><span style="color: black; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">, </span><span style="color: grey; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">"NewCreatedReport"</span><span style="color: black; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">, </span><span style="color: grey; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">"/"</span><span style="color: black; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">, </span><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">false</span><span style="color: black; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">, reportDefinition, </span><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">null</span><span style="color: black; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">, warnings)</span><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;">;</span></span></span></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<br /></div>
<span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;"><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;"><span style="color: blue; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: Tahoma; mso-bidi-language: AR-SA; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-US;"><div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="color: black; font-family: Calibri; font-size: small;">After executing this code a new report will get created with report name/title as “</span><span style="color: grey; font-family: "Lucida Console"; font-size: 9pt; line-height: 115%; mso-bidi-font-family: Tahoma;">NewCreatedReport”</span><span style="color: black; font-family: Calibri; font-size: small;"> on root of reportServer i.e <span style="color: grey; font-family: Lucida Console; font-size: x-small;"><a href="http://localhost/Reports">http://localhost/Reports</a></span></span></div>
<br /><br /></span></span></span></span></div>
Narendrahttp://www.blogger.com/profile/13112817201598525701noreply@blogger.com3tag:blogger.com,1999:blog-5924588680683817425.post-81302524277594881272011-09-16T00:37:00.001+05:302011-10-13T19:43:39.243+05:30Print SSRS Report using ReportExecutionService<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="color: blue; font-family: Consolas; font-size: x-small;"></span><br />
<br />
This post explains about programmatically rendering a report and then sending that report directly to a local or network printer using C# and the Reporting Services Web service.<br />
PreRequisite : You must have SSRS(SQL Server Reporting Services) installed so that you can use Reporting web services provided by SSRS.<br />
<br />
Step 1: <strong>Add Reference to Web <span style="font-family: inherit;">Service</span>()</strong><br />
<br />
<span style="font-family: Verdana; font-size: x-small;">The first thing you need to do is add a Web reference to the Reporting Services Web service in your development project that points to your report server. </span><br />
<span style="font-family: Verdana; font-size: x-small;">To do so right-click on your project in Visual Studio and choose <strong>Add Service reference...</strong></span> .Then Click on <strong>Advanced</strong> and then <strong>"Add Web Reference.."</strong> as shown in below image..<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-Df9UxkMRwF8/TnI928JcawI/AAAAAAAAACg/uFGCOwj5BIc/s1600/Add+Service+Reference.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" closure_uid_mxjx6n="146" height="140" rba="true" src="http://3.bp.blogspot.com/-Df9UxkMRwF8/TnI928JcawI/AAAAAAAAACg/uFGCOwj5BIc/s320/Add+Service+Reference.jpg" width="320" /></a></div>
<br />
<div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;">
<span style="font-family: Verdana; font-size: x-small;">Provide report server URL (in my case <a href="http://localhost/reportserver/ReportExecution2005.asmx">http://localhost/reportserver/ReportExecution2005.asmx</a>). If you have a remote report server, simply change the URL of the Web reference. The end point for any Reporting Services Web service is <a href="http://servername/reportserver/reportservice.asmx">http://servername/reportserver/reportservice.asmx</a>.</span></div>
<span style="font-family: Verdana; font-size: x-small;">Provide service reference name(i provided "ExecutionService" as reference name) and click on Add.</span><br />
<br />
<div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;">
<a href="http://2.bp.blogspot.com/-4RnLwMmmu10/TnJA1kabvmI/AAAAAAAAACo/qe8Yl1lZv44/s1600/s.jpg" imageanchor="1" style="clear: right; cssfloat: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" closure_uid_mxjx6n="364" height="145" rba="true" src="http://2.bp.blogspot.com/-4RnLwMmmu10/TnJA1kabvmI/AAAAAAAAACo/qe8Yl1lZv44/s200/s.jpg" width="200" /></a><span style="font-family: Verdana; font-size: x-small;">now service reference gets added to user solution as shown below</span></div>
<div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;">
<br /></div>
<div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;">
<br /></div>
<div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;">
<br /></div>
<div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;">
<br /></div>
<div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;">
<br /></div>
<div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;">
<br /></div>
<div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;">
<br /></div>
<div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;">
Step 2: <strong>Using ReportingService.Render() method to Render report in desired format:</strong></div>
<div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;">
<span style="font-family: Verdana; font-size: x-small;">Once you have added the appropriate Web reference, create a proxy object for the Web service, so that you can access the its methods. </span></div>
<div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;">
<span style="font-family: Verdana; font-size: x-small;">The method that we are most interested in for the purpose of this article is the <strong>ReportingService.Render</strong> method. This is the primary method for rendering reports that have been published to the report server.</span></div>
<br />
<span style="font-family: inherit; font-size: x-small;">The syntax for the Render method is as follows:</span><br />
<span style="font-family: inherit;"></span><br />
<pre class="csharpcode"><span style="font-family: inherit;"><span class="kwrd">public</span> Byte[] Render(<span class="kwrd">string</span> Report,<span class="kwrd">string</span> Format,<span class="kwrd">string</span> HistoryID,<span class="kwrd">string</span> DeviceInfo,
[Namespace].ParameterValue[] Parameters,[Namespace].DataSourceCredentials[] Credentials,
<span class="kwrd">string</span> ShowHideToggle,<span class="kwrd">out</span> <span class="kwrd">string</span> Encoding,<span class="kwrd">out</span> <span class="kwrd">string</span> MimeType,</span></pre>
<div class="csharpcode">
<span style="font-family: inherit;"><span class="kwrd">out</span> [Namespace].ParameterValue[] ParametersUsed, <span class="kwrd">out</span> [Namespace].Warning[] Warnings,</span></div>
<div class="csharpcode">
<span style="font-family: inherit;"><span class="kwrd">out</span> <span class="kwrd">string</span>[] StreamIds); </span></div>
<br />
<span style="font-family: Verdana; font-size: x-small;">In code, you need to render to the Image output format designated by the <em>Format</em> argument. The value of this parameter is a string, simply "IMAGE". To get Enhanced Meta File (EMF) output, the kind of output you will need for printing, you also need to specify device information for the call to <strong>Render</strong>. That device information should be passed as an XML string for the <em>DeviceInfo</em> argument and should look like "<DeviceInfo><OutputFormat>EMF</OutputFormat></DeviceInfo>". The Render method returns the report as a base 64-encoded byte array. This array of bytes can be used to perform a number of functions including saving the output to a file on the hard drive, or more importantly, sending the bytes as a stream to a printer.</span><br />
<br />
<br />
<span style="font-family: Verdana; font-size: x-small;">Step 3:<span style="font-family: Verdana; font-size: small;"><strong>Printing the Report Programmatically</strong></span></span><br />
<span style="font-family: Verdana; font-size: x-small;"><span style="font-size: small;">Here we </span><span style="font-size: x-small;">use the classes of the System.Drawing.Printing namespace in order to send EMF output to a printer</span></span><br />
<span style="font-family: Verdana; font-size: x-small;">From a Reporting Services standpoint, the key challenge is determining how many pages there are in the report. The SOAP API for Reporting Services lacks the ability to evaluate a report's number of printed pages through any exposed report properties. So the trick is to determine how many pages there are through some other means.</span><br />
<br />
<span style="font-size: x-small;"><span style="font-family: Verdana;">The MSDN documentation for <strong>Render</strong> method says that it returns the results of the rendered report as a byte array, but it only sends back the first page. Subsequent pages are associated with the report as streams with accompanying stream IDs. By counting the number of <strong>StreamIDs</strong> in the resultant string array, you can determine how many pages are in the report.</span></span><br />
<span style="font-family: Verdana; font-size: x-small;"><span style="font-size: small;">But i think we get this StreamIDs as empty array everytime .....so we have to use another logic to find number of pages and their stream .....you can find this logic in my below code :</span></span><br />
<br />
<span style="font-family: Verdana; font-size: x-small;">Once you know how many pages you are dealing with you can call the <strong>Render</strong> method for each page in the report and send that page to the printer. You can render specific pages using device information. The device information for this is <em>StartPage</em>.</span><br />
<br />
<span style="font-family: Verdana; font-size: x-small;">i have used <span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;">PrintDocument class <span style="color: black;">to print the report...</span></span></span></span></span><br />
<br />
<span style="font-family: Verdana; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: black;">Following is the code to achieve this functionality...</span></span></span></span></span><br />
<br />
<br />
<span style="font-family: Verdana; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: black;"> System;</span></span></span></span></span></span></span><br />
<span style="font-family: Verdana; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: black;"> System.Web;</span></span></span></span></span></span></span><br />
<span style="font-family: Verdana; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: black;"> System.Configuration;</span></span></span></span></span></span></span><br />
<span style="font-family: Verdana; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: black;"> System.Drawing.Printing;</span></span></span></span></span></span></span><br />
<span style="font-family: Verdana; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: black;"> System.Drawing;</span></span></span></span></span></span></span><br />
<span style="font-family: Verdana; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: black;"> System.IO;</span></span></span></span></span></span></span><br />
<span style="font-family: Verdana; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: black;"> System.Drawing.Imaging;</span></span></span></span></span></span></span><br />
<span style="font-family: Verdana; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: black;"> System.Runtime.InteropServices;</span></span></span></span></span></span></span><br />
<span style="font-family: Verdana; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: black;"> DirectlyPrintReport.ExecutionService;</span></span></span></span></span></span></span><br />
<span style="font-family: Verdana; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">using</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: black;"> System.Security.Principal;</span></span></span></span></span></span></span><br />
<span style="font-family: Verdana; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><br /><br /><br /><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">namespace <span style="color: black;">DirectlyPrintReport</span><br />{</span></span></span></span></span><br /><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"> public</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">class</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;">PrintManager</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span></span></span><br /><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">{<br /><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"></span></span><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;"></span></span></span></span></span></span></span><br /><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;"><span style="color: green; font-family: Consolas; font-size: x-small;">// class members </span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><br /></span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">private</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;">ReportExecutionService</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> rs = </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">new</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;">ReportExecutionService</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">();</span></span></span></span></span></span><br /><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">private</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">byte</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">[][] m_renderedReport;</span></span></span></span></span></span><br /><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">private</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;">Graphics</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">.</span></span><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;">EnumerateMetafileProc</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> m_delegate = </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">null</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">;</span></span></span></span></span></span><br /><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">private</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;">MemoryStream</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> m_currentPageStream;</span></span></span></span></span></span><br /><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">private</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;">Metafile</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> m_metafile = </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">null</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">;</span></span></span></span></span></span><br /><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">private</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">int</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> m_numberOfPages;</span></span></span></span></span></span><br /><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">private</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">int</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> m_currentPrintingPage;</span></span></span></span></span></span><br /><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">private</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">int</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> m_lastPrintingPage;</span></span><br /><br /><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">public <span style="color: black;">PrintManager()</span><br />{ <br />rs.Credentials = System.Net.<span style="color: #2b91af;">CredentialCache</span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">.DefaultNetworkCredentials;</span></span><br />}</span></span></span></span></span></span></span><br /><br /><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: black;"> </span></span></span><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;"><span style="color: blue; font-family: Consolas; font-size: x-small;">public <span style="color: black;"> PrintManager(System.Net.</span><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;"><span style="color: #2b91af; font-family: Consolas; font-size: x-small;">NetworkCredential</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="color: black;"> credentials)</span></span></span><br />{<br />rs.Credentials = credentials;<br />}</span></span></span></span></span></span></span></span></span></span></span></span></span></span><br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">bool</span> PrintReport(<span style="color: blue;">string</span> reportPath, ExecutionService.<span style="color: #2b91af;">ParameterValue</span>[] parameters, <span style="color: blue;">int</span> fromPage, <span style="color: blue;">int</span> toPage)</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">this</span>.m_renderedReport = <span style="color: blue;">this</span>.RenderReport(reportPath, parameters);</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">try</span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// Wait for the report to completely render. </span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">if</span> (m_numberOfPages < 1)</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> { </span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">return</span> <span style="color: blue;">false</span>;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//You can set the Required Printer Settings(Paper Size, Page Source, Orientation etc) in printerSettings object defined below</span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">PrinterSettings</span> printerSettings = <span style="color: blue;">new</span> <span style="color: #2b91af;">PrinterSettings</span>();</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> printerSettings.MaximumPage = m_numberOfPages;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> printerSettings.MinimumPage = 1;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> printerSettings.PrintRange = <span style="color: #2b91af;">PrintRange</span>.AllPages;<span style="color: green;">//PrintRange.SomePages;</span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">PrintDocument</span> pd = <span style="color: blue;">new</span> <span style="color: #2b91af;">PrintDocument</span>();</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">if</span> (toPage != -1 && fromPage != -1)</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> m_currentPrintingPage = fromPage;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> m_lastPrintingPage = toPage;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">if</span> (m_numberOfPages < toPage)</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> toPage = m_numberOfPages;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> m_lastPrintingPage = toPage;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">if</span> (m_numberOfPages < fromPage)</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> fromPage = m_numberOfPages;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> m_currentPrintingPage = fromPage;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> printerSettings.FromPage = fromPage;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> printerSettings.ToPage = toPage;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"Printing report... Start Page:{0} End Page:{1} Total Page(s):{2}"</span>, fromPage, toPage, m_numberOfPages);</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">else</span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> m_currentPrintingPage = 1;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> m_lastPrintingPage = m_numberOfPages;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"Printing report..."</span>);</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">using</span> (<span style="color: #2b91af;">WindowsImpersonationContext</span> wic = <span style="color: #2b91af;">WindowsIdentity</span>.Impersonate(<span style="color: #2b91af;">IntPtr</span>.Zero))</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//code to send printdocument to the printer</span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//Set Your Printer Name here</span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> printerSettings.PrinterName = <span style="color: #a31515;">"Microsoft XPS Document Writer"</span>; </span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> pd.PrinterSettings = printerSettings;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> pd.PrintPage += <span style="color: blue;">this</span>.pd_PrintPage;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> pd.Print();</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">catch</span> (<span style="color: #2b91af;">Exception</span> ex)</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//System.Windows.Forms.MessageBox.Show(ex.ToString());</span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Console</span>.WriteLine(ex.Message);</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">return</span> <span style="color: blue;">true</span>;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary></span><span style="color: green;"> </span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: grey;">///</span><span style="color: green;"> This method renders the report as multidimentional byte array. </span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary></span><span style="color: green;"> </span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">private</span> <span style="color: blue;">byte</span>[][] RenderReport(<span style="color: blue;">string</span> reportPath, ExecutionService.<span style="color: #2b91af;">ParameterValue</span>[] parameters)</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// Private variables for rendering </span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">string</span> historyId = <span style="color: blue;">null</span>;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> ExecutionService.<span style="color: #2b91af;">ExecutionHeader</span> execHeader = <span style="color: blue;">new</span> ExecutionService.<span style="color: #2b91af;">ExecutionHeader</span>();</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">try</span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> rs.Timeout = 300000;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> rs.ExecutionHeaderValue = execHeader;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> rs.LoadReport(reportPath, historyId);</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">if</span> ((parameters != <span style="color: blue;">null</span>))</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> rs.SetExecutionParameters(parameters, <span style="color: #a31515;">"en_us"</span>);</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">byte</span>[][] pages = <span style="color: blue;">new</span> <span style="color: #2b91af;">Byte</span>[0][];</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">string</span> format = <span style="color: #a31515;">"IMAGE"</span>;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">int</span> numberOfPages = 1;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">byte</span>[] currentPageStream = <span style="color: blue;">new</span> <span style="color: blue;">byte</span>[1] { 0x00 }; <span style="color: green;">// put a byte to get the loop started</span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">string</span> extension = <span style="color: blue;">null</span>;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">string</span> encoding = <span style="color: blue;">null</span>;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">string</span> mimeType = <span style="color: blue;">null</span>;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">string</span>[] streamIDs = <span style="color: blue;">null</span>;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> ExecutionService.<span style="color: #2b91af;">Warning</span>[] warnings = <span style="color: blue;">null</span>;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">while</span> (currentPageStream.Length > 0)</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">string</span> deviceInfo = <span style="color: #2b91af;">String</span>.Format(<span style="color: #a31515;">@"<DeviceInfo><OutputFormat>EMF</OutputFormat><PrintDpiX>200</PrintDpiX><PrintDpiY>200</PrintDpiY>"</span> + <span style="color: #a31515;">"<StartPage>{0}</StartPage></DeviceInfo>"</span>, numberOfPages);</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//rs.Render will render the page defined by deviceInfo's <StartPage>{0}</StartPage> tag</span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> currentPageStream = rs.Render(format, deviceInfo, <span style="color: blue;">out</span> extension, <span style="color: blue;">out</span> encoding, <span style="color: blue;">out</span> mimeType, <span style="color: blue;">out</span> warnings, <span style="color: blue;">out</span> streamIDs);</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">if</span> (currentPageStream.Length == 0 && numberOfPages == 1)</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//renderException = EnumRenderException.ZERO_LENGTH_STREAM;</span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">break</span>;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//Add the byte stream of current page in pages[] array so that we can have complete report in pages[][] array</span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">if</span> (currentPageStream.Length > 0)</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Array</span>.Resize(<span style="color: blue;">ref</span> pages, pages.Length + 1);</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> pages[pages.Length - 1] = currentPageStream;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> numberOfPages++;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> m_numberOfPages = numberOfPages - 1;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">return</span> pages;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">catch</span> (System.Web.Services.Protocols.<span style="color: #2b91af;">SoapException</span> ex)</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Console</span>.WriteLine(ex.Detail.InnerXml);</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">catch</span> (<span style="color: #2b91af;">Exception</span> ex)</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Console</span>.WriteLine(ex.Message);</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">finally</span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// Console.WriteLine("Number of pages: {0}", pages.Length);</span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">return</span> <span style="color: blue;">null</span>;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: grey;">///</span><span style="color: green;"> Handle the Printing of each page</span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param name="sender"></param></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param name="ev"></param></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">private</span> <span style="color: blue;">void</span> pd_PrintPage(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">PrintPageEventArgs</span> ev)</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> ev.HasMorePages = <span style="color: blue;">false</span>;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">if</span> (m_currentPrintingPage <= m_lastPrintingPage && MoveToPage(m_currentPrintingPage))</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// Draw the page </span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> ReportDrawPage(ev.Graphics);</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// If the next page is less than or equal to the last page, </span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// print another page. </span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">if</span> (System.Threading.<span style="color: #2b91af;">Interlocked</span>.Increment(<span style="color: blue;">ref</span> m_currentPrintingPage) <= m_lastPrintingPage)</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> ev.HasMorePages = <span style="color: blue;">true</span>;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// Method to draw the current emf memory stream </span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">private</span> <span style="color: blue;">void</span> ReportDrawPage(<span style="color: #2b91af;">Graphics</span> g)</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">if</span> (m_currentPageStream == <span style="color: blue;">null</span> || 0 == m_currentPageStream.Length || m_metafile == <span style="color: blue;">null</span>)</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">return</span>;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">lock</span> (<span style="color: blue;">this</span>)</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// Set the metafile delegate. </span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">int</span> width = m_metafile.Width;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">int</span> height = m_metafile.Height;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> m_delegate = <span style="color: blue;">new</span> <span style="color: #2b91af;">Graphics</span>.<span style="color: #2b91af;">EnumerateMetafileProc</span>(MetafileCallback);</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// Draw in the rectangle </span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//Point destPoint = new Point(0, 0);</span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Point</span>[] points = <span style="color: blue;">new</span> <span style="color: #2b91af;">Point</span>[3];</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Point</span> destPoint = <span style="color: blue;">new</span> <span style="color: #2b91af;">Point</span>(0, 0);</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Point</span> destPoint1 = <span style="color: blue;">new</span> <span style="color: #2b91af;">Point</span>(width/2 , 0);</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Point</span> destPoint2 = <span style="color: blue;">new</span> <span style="color: #2b91af;">Point</span>(0, height/2);</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> points[0] = destPoint;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> points[1] = destPoint1;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> points[2] = destPoint2;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> g.EnumerateMetafile(m_metafile, points, m_delegate);</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// Clean up </span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> m_delegate = <span style="color: blue;">null</span>;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">private</span> <span style="color: blue;">bool</span> MoveToPage(<span style="color: blue;">int</span> page)</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// Check to make sure that the current page exists in </span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// the array list </span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">if</span> (m_renderedReport[m_currentPrintingPage - 1] == <span style="color: blue;">null</span>)</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">return</span> <span style="color: blue;">false</span>;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// Set current page stream equal to the rendered page </span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> m_currentPageStream = <span style="color: blue;">new</span> <span style="color: #2b91af;">MemoryStream</span>(m_renderedReport[m_currentPrintingPage - 1]);</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// Set its postion to start. </span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> m_currentPageStream.Position = 0;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// Initialize the metafile </span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">if</span> (m_metafile != <span style="color: blue;">null</span>)</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> m_metafile.Dispose();</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> m_metafile = <span style="color: blue;">null</span>;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// Load the metafile image for this page </span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> m_metafile = <span style="color: blue;">new</span> <span style="color: #2b91af;">Metafile</span>((<span style="color: #2b91af;">Stream</span>)m_currentPageStream);</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">return</span> <span style="color: blue;">true</span>;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">private</span> <span style="color: blue;">bool</span> MetafileCallback(<span style="color: #2b91af;">EmfPlusRecordType</span> recordType, <span style="color: blue;">int</span> flags, <span style="color: blue;">int</span> dataSize, <span style="color: #2b91af;">IntPtr</span> data, <span style="color: #2b91af;">PlayRecordCallback</span> callbackData)</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">byte</span>[] dataArray = <span style="color: blue;">null</span>;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// Dance around unmanaged code. </span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">if</span> (data != <span style="color: #2b91af;">IntPtr</span>.Zero)</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// Copy the unmanaged record to a managed byte buffer </span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// that can be used by PlayRecord. </span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> dataArray = <span style="color: blue;">new</span> <span style="color: blue;">byte</span>[dataSize];</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Marshal</span>.Copy(data, dataArray, 0, dataSize);</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// play the record. </span></span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> m_metafile.PlayRecord(recordType, flags, dataSize, dataArray);</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">return</span> <span style="color: blue;">true</span>;</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">}</span></div>
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<br />
<br />
<br />
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="font-family: Calibri;">Call this “</span><b style="mso-bidi-font-weight: normal;"><span style="font-family: Consolas; font-size: 9.5pt; line-height: 115%;">PrintReport</span></b><span style="font-family: Consolas; font-size: 9.5pt; line-height: 115%;"> function” from any event(eg.A button click) from where you want to print the Server Report and pass the “report path as parameter” to the function.</span></div>
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 115%;">Also you need to pass report’s parameters as parameter to this function…..in my case my report do not have any parameter so I am passing null</span></div>
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">In my case my server reportPath is <span style="color: #a31515;">"/EmpInfoReport/EmpDetails"</span></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="font-family: Calibri, sans-serif;">I will call this function on my Print button click as follows:</span><br />
<span style="color: blue; font-family: Consolas; font-size: 10pt;">private</span><span style="font-family: Consolas; font-size: 10pt;"> <span style="color: blue;">void</span> btnPrint_Click(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e)<br />{<br />DirectlyPrintReport.<span style="color: #2b91af;">PrintManager</span> objPrintManager = <span style="color: blue;">new</span> <span style="color: #2b91af;">PrintManager</span>();<br />objPrintManager.PrintReport(<span style="color: #a31515;">@"/EmpInfoReport/EmpDetails"</span>, <span style="color: blue;">null</span>, -1, -1);<br />} </span><br />
<span style="font-family: Consolas; font-size: 10pt;"><br /></span><br />
<span style="font-family: Consolas; font-size: 10pt;">You can check following related post as well</span><br />
<span style="font-family: Consolas; font-size: 10pt;"><span class="Apple-style-span" style="background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; line-height: 18px;"></span></span><br />
<h3 class="post-title entry-title" style="color: black; font: normal normal bold 22px/normal Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; position: relative;">
<span style="font-family: Consolas; font-size: 10pt;">Copy SSRS Report on Report Server Programatically</span></h3>
<div>
<span style="font-family: Consolas; font-size: 10pt;"><a href="http://programmingssrs.blogspot.com/2011/10/copy-ssrs-report-on-report-server.html">http://programmingssrs.blogspot.com/2011/10/copy-ssrs-report-on-report-server.html</a></span></div>
<span style="font-family: Consolas; font-size: 10pt;"><span class="Apple-style-span" style="background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; line-height: 18px;"><h3 class="post-title entry-title" style="color: black; font: normal normal bold 22px/normal Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; position: relative;">
Create a New SSRS report Programmatically</h3>
<div>
<a href="http://programmingssrs.blogspot.com/2011/10/create-new-ssrs-report-programmatically.html">http://programmingssrs.blogspot.com/2011/10/create-new-ssrs-report-programmatically.html</a></div>
<div>
<br /></div>
<div>
Please let me know is it helpful....</div>
</span></span></div>
</div>
</div>Narendrahttp://www.blogger.com/profile/13112817201598525701noreply@blogger.com11