{"id":634,"date":"2008-01-04T19:47:32","date_gmt":"2008-01-05T02:47:32","guid":{"rendered":"http:\/\/members.crystalreportsbook.com\/crystal-reports-xi\/1414-c-code-listings\/"},"modified":"2008-01-04T19:47:32","modified_gmt":"2008-01-05T02:47:32","slug":"1414-c-code-listings","status":"publish","type":"post","link":"http:\/\/www.crystalreportsonlinetraining.com\/training\/1414-c-code-listings\/","title":{"rendered":"14.14 C# Code Listings"},"content":{"rendered":"<h1>C# Code Listings<\/h1>\n<p>The C# code listings are equivalent to the VB.NET code listings.<\/p>\n<p>         <code_Caption>Listing 14-1. A template for modifying reports.<\/code_Caption><br \/>\n         <code>private void Form1_Load(object sender, System.EventArgs e)<\/code><br \/>\n         <code>{<\/code><br \/>\n         <code>CrystalReport1 MyReport = new CrystalReport1();<\/code><br \/>\n         <code>\/\/Call all report modification code here.<\/code><br \/>\n         <code>\/\/For illustration purposes, I'm calling a generice method that changes the report title.<\/code><br \/>\n         <code>\/\/The code for ModifyTitle() isn't shown here.<\/code><br \/>\n         <code>ModifyTitle(MyReport, \"Runtime Demo\");<\/code><br \/>\n         <code>crystalReportViewer1.ReportSource = MyReport;<\/code><br \/>\n         <code>}<\/code><br \/>\n         <code_Caption>Listing 14-2. Template for ASP.NET pages.<\/code_Caption><br \/>\n         <code>private void Page_Load(object sender, System.EventArgs e)<\/code><br \/>\n         <code>{<\/code><br \/>\n         <code>CrystalDecisions.CrystalReports.Engine.ReportDocument MyReport;<\/code><br \/>\n         <code>if (!IsPostBack) {<\/code><br \/>\n         <code>MyReport = new CrystalReport1();<\/code><br \/>\n         <code>\/\/Call all report modification code here.<\/code><br \/>\n         <code>\/\/For illustration purposes, I'm calling a generice method that changes the report title.<\/code><br \/>\n         <code>\/\/The code for ModifyTitle() isn't shown here.<\/code><br \/>\n         <code>ModifyTitle(MyReport, \"Runtime Demo\");<\/code><br \/>\n         <code>Session[\"MyReport\"] = MyReport;<\/code><br \/>\n         <code>} else  {<\/code><br \/>\n         <code>MyReport = (CrystalDecisions.CrystalReports.Engine.ReportDocument)Session[\"MyReport\"];<\/code><br \/>\n         <code>}<\/code><br \/>\n         <code>CrystalReportViewer1.ReportSource = MyReport;<\/code><br \/>\n         <code>}<\/code><br \/>\n         <code_Caption>Listing 14-3. Forcing garbage collection in an ASP.NET page.<\/code_Caption><br \/>\n         <code>private void WebForm1_Init(object sender, System.EventArgs e)<\/code><br \/>\n         <code>{<\/code><br \/>\n         <code>if (MyReport!=null) {<\/code><br \/>\n         <code>MyReport.Close();<\/code><br \/>\n         <code>MyReport.Dispose();<\/code><br \/>\n         <code>GC.Collect();<\/code><br \/>\n         <code>}<\/code><br \/>\n         <code>}<\/code><br \/>\n         <code_Caption>Listing 14-4. Change a report&#8217;s printer settings.<\/code_Caption><br \/>\n         <code>CrystalReport1 MyReport = new CrystalReport1();<\/code><br \/>\n         <code>MyReport.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape;<\/code><br \/>\n         <code>MyReport.PrintOptions.PrinterName = \"HP LasterJet510\";<\/code><br \/>\n         <code>MyReport.PrintToPrinter(1, false, 0, 0);<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>C# Code Listings The C# code listings are equivalent to the VB.NET code listings. Listing 14-1. A template for modifying reports. private void Form1_Load(object sender, System.EventArgs e) { CrystalReport1 MyReport = new CrystalReport1(); \/\/Call all report modification code here. \/\/For illustration purposes, I&#8217;m calling a generice method that changes the report title. \/\/The code for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34,2],"tags":[],"class_list":["post-634","post","type-post","status-publish","format-standard","hentry","category-chapter-14-programming-reports","category-crystal-reportsnet-2003","entry"],"_links":{"self":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/634","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/comments?post=634"}],"version-history":[{"count":0,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/634\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/media?parent=634"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/categories?post=634"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/tags?post=634"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}