H
Henry
I am trying to write an application that allows me to dynamically load
selected Crystal Report files, read the parameters from the report file,
give the user a chance to enter relevant data in a user friendly manner and
then run the report in a report viewer.
I can find bits and pieces of the instructions for doing this, but I don't
seem to be able to put it all together. For now I have some code that will
show a file Open dialog and let me select the report file. The next step I
believe is to load that file into a Report document. Once the document is
loaded, then I should be able to access its parameterFieldInfo. Here is
code I have cobbled together so far:
// I open the dialog by clicking a command button
private void button1_Click(object sender, System.EventArgs e)
{
// Displays an OpenFileDialog so the user can select a Cursor.
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "Report Files (*.rpt)|*.rpt";
openFileDialog1.Title = "Select a Report File";
// Show the Dialog.
// If the user clicked OK in the dialog and a .RPT file was selected, then
open it.
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
// I thought the next line of code would load the file into the Report
Dcoument, but I get the error below.
//An unhandled exception of type 'System.NullReferenceException' occurred in
ReportManager.exe
ReportDocument1.Load(openFileDialog1.FileName);
//I am not quite sure how to access the values in the parameter fields They
are part of the Crystal Report Engine DataDefinition object, and so is the
Report document, but I don't understand the link..
for( int i =0 ;i< dataDef1.ParameterFields.Count;i++)
{
listBox1.Items.Add(dataDef1.ParameterFields.Current.ToString());
dataDef1.ParameterFields.MoveNext();
}
}
}
selected Crystal Report files, read the parameters from the report file,
give the user a chance to enter relevant data in a user friendly manner and
then run the report in a report viewer.
I can find bits and pieces of the instructions for doing this, but I don't
seem to be able to put it all together. For now I have some code that will
show a file Open dialog and let me select the report file. The next step I
believe is to load that file into a Report document. Once the document is
loaded, then I should be able to access its parameterFieldInfo. Here is
code I have cobbled together so far:
// I open the dialog by clicking a command button
private void button1_Click(object sender, System.EventArgs e)
{
// Displays an OpenFileDialog so the user can select a Cursor.
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "Report Files (*.rpt)|*.rpt";
openFileDialog1.Title = "Select a Report File";
// Show the Dialog.
// If the user clicked OK in the dialog and a .RPT file was selected, then
open it.
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
// I thought the next line of code would load the file into the Report
Dcoument, but I get the error below.
//An unhandled exception of type 'System.NullReferenceException' occurred in
ReportManager.exe
ReportDocument1.Load(openFileDialog1.FileName);
//I am not quite sure how to access the values in the parameter fields They
are part of the Crystal Report Engine DataDefinition object, and so is the
Report document, but I don't understand the link..
for( int i =0 ;i< dataDef1.ParameterFields.Count;i++)
{
listBox1.Items.Add(dataDef1.ParameterFields.Current.ToString());
dataDef1.ParameterFields.MoveNext();
}
}
}