Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
Hi,
I am trying to export crystal report in order to mail it. I have used :
printbanqoute.ExportToDisk(ExportFormatType.PortableDocFormat, "E:\\ASD.pdf");

However I get an error the "Missing Parameter Values".
Without using ExportToDisc it works fine.
I have used 4 parameters and checked each one of them it has values, heres how i used :
ParameterFields paramFields = new ParameterFields();
                ParameterField paramField = new ParameterField();
                ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
                paramField.Name = "phoneno";
                paramDiscreteValue.Value = BLDashboard.phoneno;
                paramField.CurrentValues.Add(paramDiscreteValue);
                paramFields.Add(paramField);

                paramField = new ParameterField(); // <-- This line is added
                paramDiscreteValue = new ParameterDiscreteValue();  // <-- This line is added
                paramField.Name = "name";
                paramDiscreteValue.Value = BLDashboard.custname;
                paramField.CurrentValues.Add(paramDiscreteValue);
                paramFields.Add(paramField);

                paramField = new ParameterField(); // <-- This line is added
                paramDiscreteValue = new ParameterDiscreteValue();  // <-- This line is added
                paramField.Name = "address";
                paramDiscreteValue.Value = BLDashboard.add;
                paramField.CurrentValues.Add(paramDiscreteValue);
                paramFields.Add(paramField);

                paramField = new ParameterField(); // <-- This line is added
                paramDiscreteValue = new ParameterDiscreteValue();  // <-- This line is added
                paramField.Name = "email";
                paramDiscreteValue.Value = BLDashboard.email;
                paramField.CurrentValues.Add(paramDiscreteValue);
                paramFields.Add(paramField);

                crystalReportViewer1.ParameterFieldInfo = paramFields;


I googled and some one told to setdatasource before passing vlaue to parameter i tried that too but it didnt wok.
Please heclp been stucked on this for days.
Thanks

What I have tried:

I have tried check each parameter value while in breakpoint. And various codes like
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;
}


But gets error on "response" - The name 'response' does not exist in current context
Posted
Updated 26-Jan-17 18:12pm
v2
Comments
Afzaal Ahmad Zeeshan 16-Jan-17 7:29am    
What error?
markwhite1 16-Jan-17 8:15am    
The name 'response' does not exist in current context
Richard MacCutchan 16-Jan-17 9:24am    
Then you need to find out why not. No one here can guess where it is supposed to come from. Are you sure you spelled it correctly?
Richard Deeming 16-Jan-17 9:55am    
C# is case-sensitive - response is not the same as Response.
markwhite1 16-Jan-17 11:46am    
I have tried both however my main concern is why it shows "Missing Parameter value". If thats sorted I guess it would export am i right?

1 solution

I am able to solve my issue. I was writing all codes in `crystalviewer1_Load` event ie; exporting and email as well as populating data to crystal report. So I had to create a Button Email to export and email.
Heres my code to export and email, Button1 is the email button on crystalviewer:

private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         billprint.ExportToDisk(ExportFormatType.PortableDocFormat, "E:\\" + filename);
     }
     catch(Exception ex)
     {
         MessageBox.Show(ex.ToString());

     }
     try
     {
         MailMessage mm = new MailMessage();
         string toemail = BLDashboard.email;
         string custnm = BLDashboard.custname;

         mm.From = new MailAddress("operations@kaem.in", "Kashif Ahhmed");
         mm.To.Add(new MailAddress(toemail, custnm));
         mm.IsBodyHtml = true;
         string name = BLDashboard.custname;
         mm.Subject = "Bill from Indian Restaurant";
         //mm.Body = "Testing Crsytel Report Attachment send via Email";

         String Body = "<div>Hello " + name + ",<br> Thank you for considersing us for your next Party/Event, here is the Bill for the Party/Event.<br> If any queries you can reach us at 6096464445. <br> Thank You</div>";
         mm.Body = Body;
         //mm.Attachments.Add(new Attachment(rpt.ExportToStream(ExportFormatType.PortableDocFormat), fileName));
         mm.Attachments.Add(new Attachment("E:\\" + filename));



         SmtpClient sc = new SmtpClient("smtp.kaem.in");
         sc.Credentials = new NetworkCredential("emailadd", "*********");
         sc.Send(mm);
         // MailMessage msg = mm.CreateMailMessage("mr.markwhite1@gmail.com", replacements, Body, new System.Web.UI.Control());
         MessageBox.Show("Email successfully sent to " + toemail);
     }
     catch (Exception e1)
     {

         MessageBox.Show("Unable to send email to mr.markwhite1@gmail.com due to following error:\n\n" + e1.Message, "Email send error", MessageBoxButtons.OK, MessageBoxIcon.Error);

         //{
         //    this.SendEmail(emailId, subject, body, rpt, fileName);
         //}
     }
 }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900