If you want to print a local .rdlc report, you can't use the property "ShowPrintButton" for the reportviewer control. This property event it is set to true, will work only when the report is processed remote (ProcessingMode=remote), case when you have to install Reporting Services where to deploy your report.
But, if you don't want to install Reporting Services, but you want to have the facility to print your report, a solution is to save locally as .pdf your report and after that to open directely the file to your user. So, the user can just print the opened file using print button from Adobe Reader.
In my example, I have write a method wich reveive as parameter an report viewer object, and the page where the report viewer is containing:
public static void PrintLocalRdlc(Microsoft.Reporting.WebForms.ReportViewer rwRpt, Page page)
{
DirectoryInfo di = new DirectoryInfo(HttpContext.Current.Server.MapPath("~/Upload/"));
foreach (FileInfo fi in di.GetFiles())
{
if (fi.Name.IndexOf("_"
+ HttpContext.Current.Session.SessionID
+ "_")
!= -1)
{
fi.Delete();
}
}
string mimeType;
string encoding;
string fileNameExtension;
string[] streams;
Warning[] warnings;
byte[] pdfContent
= rwRpt.LocalReport.Render
("PDF", null, out mimeType, out encoding, out fileNameExtension,
out streams, out warnings);
string realUrl = "~/Upload/Report_"
+ HttpContext.Current.Session.SessionID
+ "_"
+ Guid.NewGuid().ToString()
+ ".pdf";
string pdfPath
= HttpContext.Current.Server.MapPath(realUrl);
System.IO.FileStream pdfFile = new System.IO.FileStream(pdfPath, System.IO.FileMode.Create);
pdfFile.Write(pdfContent, 0, pdfContent.Length);
pdfFile.Close();
string windowOpen = "printWin = window.open('" + page.ResolveUrl(realUrl) + "', '_blank','height=800,left=100,top=100,width=1200,toolbar=no,titlebar=0,status=0,menubar=yes,location=no,scrollb ars=1' " + ");printWin.focus();self.print();";
page.ClientScript.RegisterStartupScript(page.GetType(), Guid.NewGuid().ToString(), windowOpen, true);
}
The example can be downloaded from PrintLocalRdlc.zip