Export Crystal Report via C#

G

Guest

Hi,

If there is a more appropriate group for this, please point me in the right
direction.

I have a Crystal Report .rpt file that I can get to launch from my code and
I can view it. I pass in parameters to the Viewer and all seems to work
fine. Where it blows up is when I try to export it to a PDF. I've tried
many different combination of examples I've found floating around on the
Internet and all seem to have issues.

The error I'm getting is:
CrystalDecisions.CrystalReport.Engine.ParameterFieldCurrentValueException:
Missing parameter values.

Am I correct in my assumption that passing parameters to the viewer isn't
the same as passing them to the report and is this the problem?

Below is my code. You can see that I have commented out rpt.ExportToDisk()
in the try block as this didn't work either.

Thanks VERY much in adavance,
John F
-------------------
ReportDocument rpt = new ReportDocument();
ParameterFields paramFields = new ParameterFields ();
ParameterField paramField = new ParameterField ();
ParameterDiscreteValue discreteVal = new ParameterDiscreteValue ();


// Set the name of the parameter field, this must match a
// parameter in the report.
paramField.ParameterFieldName = "year_rpt";

// Set the first discrete value and pass it to the parameter.
discreteVal.Value = "2005";
paramField.CurrentValues.Add (discreteVal);

// Add the parameter to the parameter fields collection.
paramFields.Add (paramField);

// The paramField variable for the seconda parameter
// is set to new so the previous settings will not be overwritten.
paramField = new ParameterField ();

// Set the name of the parameter field, this must match a
// parameter in the report.
paramField.ParameterFieldName = "location";

// Set the second discrete value and pass it to the parameter.
discreteVal = new ParameterDiscreteValue ();
discreteVal.Value = "LPO";
paramField.CurrentValues.Add(discreteVal);

// Add the second parameter to the parameter fields collection.
paramFields.Add (paramField);

// Set the parameter fields collection into the viewer control.
crystalReportViewer1.ParameterFieldInfo = paramFields;
rpt.Load(@"C:\locrvuytddet.rpt");
crystalReportViewer1.ReportSource = rpt;

// Define file name and path.
string filename = "c:\\test.pdf";

try
{

//rpt.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat,filename);


DiskFileDestinationOptions diskOpts =
ExportOptions.CreateDiskFileDestinationOptions();


// set export format
ExportOptions exportOpts = new ExportOptions();
exportOpts.ExportFormatType = ExportFormatType.RichText;
exportOpts.ExportDestinationType = ExportDestinationType.DiskFile;

//set the disk file options
diskOpts.DiskFileName = filename;
exportOpts.ExportDestinationOptions = diskOpts;

rpt.Export(exportOpts);

}
catch (Exception err)
{
MessageBox.Show("problems, we have problems! " + err.ToString());
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top