title: How to export Crystal report to PDF and email in c#
body: <p>I am trying to convert a crystal report to pdf as I need to mail it. So I looked tried few steps but to no avail.
  I tried:</p>
  
  <pre><code>  RPTBanQoute printbanqoute = new RPTBanQoute();
              printbanqoute.SetDataSource(ds);               
  
              printbanqoute.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, @"E:\ASD.pdf");
  </code></pre>
  
  <p>In this nothing happens.</p>
  
  <p>Then I tried :</p>
  
  <pre><code>            try
              {
                  // Export the Report to Response stream in PDF format and file name Customers
                  //printbanqoute.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "Customers");
                  printbanqoute.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "Quotation");
                  // There are other format options available such as Word, Excel, CVS, and HTML in the ExportFormatType Enum given by crystal reports
              }
              catch (Exception ex)
              {
                  Console.WriteLine(ex.Message);
                  ex = null;
              }
  </code></pre>
  
  <p>Getting an error on <code>Response</code> as <code>The name 'Response' does not exist in the current context</code></p>
  
  <p>I tried using Server.Mappath but intellisense doesnt show Mappath. I used System.Web</p>
  
  <p>Heres how I am populating data onto Crystal reprt :</p>
  
  <pre><code>  MySqlCommand cmd = new MySqlCommand("SELECT tb.BookingID, BookingDate, Event, EventDate, EventTime, Pax, Service, ServiceTime, f.FoodMenu, f.ExtraItem FROM tblBookingDetails tb, tblMenu f WHERE tb.BookingID = @bookid AND tb.BookingID = f.BookingID", con.con);
              cmd.Parameters.AddWithValue("@bookid", BLDashboard.bookingID);
              MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
              DataSet1 ds = new DataSet1();
              adapter.Fill(ds, "BookingDetails");
              if (ds.Tables["BookingDetails"].Rows.Count == 0)
              {
                  MessageBox.Show("No Data Found", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
              }
              RPTBanQoute printbanqoute = new RPTBanQoute();
              printbanqoute.SetDataSource(ds);
  </code></pre>
  
  <p>I am also passing parameter values to this Crystal report.</p>
  
  <p>So please advice how to achieve converting to PDF and email</p>
  
  <p>Also I googled further and tried these codes :</p>
  
  <pre><code> cryRpt = new ReportDocument();  
            cryRpt.Load("E:\\Office\\Clients\\Bombay Restaurant\\Banquet New - MySql\\Banquet New\\RPTBanQoute.rpt");  
            crystalReportViewer1.ReportSource = cryRpt;  
            crystalReportViewer1.Refresh();  
            try  
            {  
                ExportOptions CrExportOptions;  
                DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();  
                PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();  
                CrDiskFileDestinationOptions.DiskFileName = "c:\\csharp.net-informations.pdf";  
                CrExportOptions = cryRpt.ExportOptions;  
                {  
                    CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;  
                    CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;  
                    CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;  
                    CrExportOptions.FormatOptions = CrFormatTypeOptions;  
                }  
                cryRpt.Export();  
            }  
            catch (Exception ex)  
            {  
                MessageBox.Show(ex.ToString());  
            }  
  </code></pre>
  
  <p>But this gave me exception :
  <a href="https://i.stack.imgur.com/06bIo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/06bIo.png" alt="enter image description here"></a></p>