Hi,

I have a web application project which is done in VS2005.I am creating crystal report and i want to export it to pdf on a export button click. But an error is showing as 'Missing Parameter Value. The code i used is shown below:-

protected void btnExport_Click(object sender, EventArgs e)
    {

        System.IO.FileStream fs = null;
        long FileSize = 0;

        DiskFileDestinationOptions oDest = new DiskFileDestinationOptions();

        string ExportFileName = Server.MapPath("\\Rpt_Disbursement_search.rpt") + "Export";
        Rpt.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
        Rpt.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
        oDest.DiskFileName = ExportFileName;
        Rpt.ExportOptions.DestinationOptions = oDest;
        Rpt.Export();--ERROR IS SHOWN HERE
        Response.Clear();
        Response.Buffer = true;
        Response.AddHeader("Content-Type", "application/pdf");
        Response.AddHeader("Content-Disposition", "attachment;filename=Disbursement.pdf;");
        fs = new System.IO.FileStream(ExportFileName, FileMode.Open);
        FileSize = fs.Length;
        byte[] bBuffer = new byte[Convert.ToInt32(FileSize) + 1];
        fs.Read(bBuffer, 0, Convert.ToInt32(FileSize));
        fs.Close();
        Response.BinaryWrite(bBuffer);
        Response.Flush();
        Response.Close();

    }

I am passing a parameter to the report.There's no problem in viewing the crystal report.Wat shud i do 2 resolve the problem while exporting to pdf?

Anybody please help me 2 solve this.
Thanks In Advance,
Ranjini

Edited 3 Years Ago by mike_2000_17: Fixed formatting

try this code instead

ExportOptions CrExportOptions ;
                DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
                PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
                CrDiskFileDestinationOptions.DiskFileName = "c:\\name.pdf";
                CrExportOptions = cryRpt.ExportOptions;
                {
                    CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                    CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
                    CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
                    CrExportOptions.FormatOptions = CrFormatTypeOptions;
                }
                cryRpt.Export();

for details click here

Edited 5 Years Ago by abelLazm: n/a

Thank you for your response.But still the problem of passing parameter is there!kindly help me to resolve it..

Add try catch block and add like this

try
{
//your code
}
catch(Exception error)
{
 MessageBox.Show(error.Message + " : Exception raised in " + error.TargetSite.ToString() , error.Source.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
}

and paste the output here

Missing Parameter Values: Exception raised in Boolean ThrowDotnetException(System.Exception).
This is the exception shown in the message box.The whole code of the aspx page is shown beleow

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Text;
using System.Globalization;

using System.IO;
using System.Reflection;

//using System.Xml;
//using iTextSharp.text;
//using iTextSharp.text.pdf;
//using iTextSharp.text.html;
//using iTextSharp.text.html.simpleparser;

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Windows.Forms;

namespace EMEDICALS
{
    public partial class Report_Disbursement : System.Web.UI.Page
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["constr"]);
        SqlDataAdapter adp = new SqlDataAdapter();
        SqlCommand cmd = new SqlCommand();
        DataSet ds = new DataSet();
        Rpt_Disbursement_search Rpt = new Rpt_Disbursement_search();
        string label;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                adp = new SqlDataAdapter("Select * from tbl_District", con);
                adp.Fill(ds, "district");
                if (ds.Tables["district"].Rows.Count > 0)
                {
                    ddlDistrict.DataValueField = "int_DistrictId";
                    ddlDistrict.DataTextField = "vchr_District";
                    ddlDistrict.DataSource = ds.Tables["district"];
                    ddlDistrict.DataBind();
                    ddlDistrict.Items.Insert(0, "..SELECT..");
                }
                
            }
            //if (IsPostBack)
            //{
            //    bindreport();
            //}

           
        }

        protected void ddlDistrict_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlDistrict.SelectedItem.Text != "..SELECT..")
            {
                adp = new SqlDataAdapter("select tbl_LocalBody.int_LBId,tbl_LocalBody.vchr_LBNameEnglish,tbl_LocalBodyType.vchr_LBType from  dbo.tbl_LocalBody inner join dbo.tbl_LocalBodyType on tbl_LocalBody.int_LBTypeId=tbl_LocalBodyType.int_LBTypeId where tbl_LocalBody.int_DistrictId=" + ddlDistrict.SelectedItem.Value + " order by tbl_LocalBodyType.vchr_LBType,tbl_LocalBody.vchr_LBNameEnglish asc", con);
                adp.Fill(ds, "localbody");
                if (ds.Tables["localbody"].Rows.Count > 0)
                {

                    ddlBlock.Items.Clear();
                    ddlBlock.Items.Insert(0, "..SELECT..");
                    for (int i = 0; i < ds.Tables["localbody"].Rows.Count; i++)
                    {
                      ddlBlock.Items.Add(new ListItem(ds.Tables["localbody"].Rows[i]["vchr_LBType"].ToString() + " ... " + ds.Tables["localbody"].Rows[i]["vchr_LBNameEnglish"].ToString(), ds.Tables["localbody"].Rows[i]["int_LBId"].ToString()));

                    }
                }
            }
            else
            {
                ddlBlock.Items.Clear();
            }
            CrystalReportViewer1.Visible = false;
        }

        protected void imgbtnSubmit_Click(object sender, ImageClickEventArgs e)
        {
            bindreport();           

        }

        private void bindreport()
        {
            int f = 1;
            if (f == 1)
            {
                CrystalReportViewer1.Visible = true;
                string sql = "null";
               
                int flag = 0;
                DataSet_Emed MyDs = new DataSet_Emed();


                if (txtFrom.Text == "" && txtto.Text == "" && ddlDistrict.Text == "..SELECT.." && ddlBlock.Text == "..SELECT..")
                {

                }
                else
                {
                    sql = "SELECT     dbo.tbl_LocalBody.vchr_LBNameMalayalam, dbo.tbl_Beneficiary.vchr_NameMal, tbl_Beneficiary.vchr_HouseNoMal + ',' + tbl_Beneficiary.vchr_PlaceMal AS Address, dbo.tbl_Disbursement.flt_Amount,tbl_District.vchr_DistMalayalam,dbo.PostOffice_MST.vchr_PinCode,PostOffice_MST.vchr_BranchOffice,dbo.tbl_HeadPostOffice.vchr_HeadPostOffice,dbo.tbl_Disbursement.int_disbursementid,tbl_Disbursement.dtm_DisbursementDate FROM         dbo.tbl_LocalBody INNER JOIN dbo.tbl_Beneficiary ON dbo.tbl_LocalBody.int_LBId = dbo.tbl_Beneficiary.int_LBId INNER JOIN  dbo.tbl_Disbursement ON dbo.tbl_Beneficiary.vchr_ApplicationNo = dbo.tbl_Disbursement.vchr_ApplicationNo inner join tbl_District on dbo.tbl_Beneficiary.int_DistrictId=tbl_District.int_DistrictId inner join dbo.PostOffice_MST on dbo.PostOffice_MST.PostOfficeId=dbo.tbl_Beneficiary.int_PostOfficeId inner join dbo.tbl_HeadPostOffice on dbo.tbl_HeadPostOffice.int_HeadPostOfficeId=dbo.PostOffice_MST.int_HeadPostOfficeId where ";

                    if (txtFrom.Text != "" && txtto.Text != "")
                    {
                        if (flag == 1)
                        {
                            sql = sql + " and";
                        }
                        sql = sql + " tbl_Disbursement.dtm_DisbursementDate             between '" + DateTime.Parse(txtFrom.Text, CultureInfo.CreateSpecificCulture("en-CA")) + "' and  '" + DateTime.Parse(txtto.Text, CultureInfo.CreateSpecificCulture("en-CA")) + "'";
                        flag = 1;
                        label = "Disbursed List Within Dates " + txtFrom.Text + " and " + txtto.Text;
                        Session["lbl"] = label;
                    }

                    if (ddlDistrict.Text != "..SELECT..")
                    {
                        if (flag == 1)
                        {
                            sql = sql + " and";
                        }
                        sql = sql + " tbl_Beneficiary.int_DistrictId=" + ddlDistrict.SelectedItem.Value + "";
                        flag = 1;
                        label = label + " of District " + ddlDistrict.SelectedItem.Text;
                        Session["lbl"] = label;
                    }
                    if (ddlBlock.Text != "..SELECT.." && ddlBlock.Text != "")
                    {
                        if (flag == 1)
                        {
                            sql = sql + " and";
                        }
                        sql = sql + " tbl_Beneficiary.int_LBId=" + ddlBlock.SelectedItem.Value + "";
                        flag = 1;
                        label = label + " of Local Body  " + ddlBlock.SelectedItem.Text;
                        Session["lbl"] = label;
                    }
                }
                if (flag == 1)
                        {
                            sql = sql + " and";
                        }
                sql = sql + " bit_JDForward='true'";
                
            
                cmd.Connection = con;
                cmd.CommandText = sql;
                adp.SelectCommand = cmd;
                adp.Fill(MyDs, "Data");
                if (MyDs.Tables["Data"].Rows.Count == 0)
                {
                    ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "<script type = 'text/javascript'>window.onload=new function(){alert('No match found')};</script>");
                }
                else
                {
                    Rpt.SetDataSource(MyDs);
                    Rpt.SetParameterValue("label", label);
                    CrystalReportViewer1.ReportSource = Rpt;
                    btnExport.Visible = true;
                }
            }
            f = 0;
            
        }

      

        protected void btnExport_Click(object sender, EventArgs e)
        {
            try
            {
                System.IO.FileStream fs = null;
                long FileSize = 0;
                DiskFileDestinationOptions oDest = new DiskFileDestinationOptions();
                //Rpt.SetParameterValue("label", Session["lbl"]);
                string ExportFileName = Server.MapPath("\\Rpt_Disbursement_search.rpt") + "Export";
                Rpt.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                Rpt.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
                oDest.DiskFileName = ExportFileName;
                Rpt.ExportOptions.DestinationOptions = oDest;
                Rpt.Export();
                Response.Clear();
                Response.Buffer = true;
                Response.AddHeader("Content-Type", "application/pdf");
                Response.AddHeader("Content-Disposition", "attachment;filename=Disbursement.pdf;");
                fs = new System.IO.FileStream(ExportFileName, FileMode.Open);
                FileSize = fs.Length;
                byte[] bBuffer = new byte[Convert.ToInt32(FileSize) + 1];
                fs.Read(bBuffer, 0, Convert.ToInt32(FileSize));
                fs.Close();
                Response.BinaryWrite(bBuffer);
                Response.Flush();
                Response.Close();
            }
            catch (Exception error)
            {
                MessageBox.Show(error.Message + " : Exception raised in " + error.TargetSite.ToString(), error.Source.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

           
        
        }
      
        protected void LinkButton1_Click(object sender, EventArgs e)
        {
       
        }

         
    }
}
This article has been dead for over six months. Start a new discussion instead.