sheridan101
Programmer
I am using the following:
C#.NET
Crystal Reports.NET
Windows 2K
SQL Server 2000
and am using the following piece of code to automatically setup and export reports to disk files once the report is built. On all 8 current reports, all formats except html export with no problems using this code. It exports to html with no problems on 7 out of 8 reports. However, on one single report, I keep getting the error "Invalid export option" returned by crystal when I try to output to the either html format. The only difference between these reports is that the one that does not export to html has a subreport that gathers information from different tables and outputs to the main report. The other reports do not have such a subreport because all of the work is being done in stored procedures. I would use stored procedures for this one report but SQL does not support arrays and I need certain information arranged this way because the report has a variable number of columns across the page....
:
:
ExportOptions opt = MyReport.ExportOptions;
// drop down control containing available export formats
int RType = ExportFormat.Items.IndexOf(ExportFormat.SelectedItem);
switch( RType )
{
case 0: // adobe
ExportName = GetExportName(Location, false, false, false, false, true);
opt.ExportFormatType = ExportFormatType.PortableDocFormat;
break;
case 1: // excel
ExportName = GetExportName(Location, false, false, false, false, true);
opt.ExportFormatType = ExportFormatType.Excel;
break;
case 2: // word
ExportName = GetExportName(Location, false, false, false, false, true);
opt.ExportFormatType = ExportFormatType.WordForWindows;
break;
case 3: // rich text
ExportName = GetExportName(Location, false, false, false, false, true);
opt.ExportFormatType = ExportFormatType.RichText;
break;
case 4: // html 3.2
{
ExportName = GetExportName(Location, false, false, false, true, false);
opt.ExportFormatType = ExportFormatType.HTML32;
HTMLFormatOptions htmlOpts = new HTMLFormatOptions ();
htmlOpts.HTMLFileName = ExportName;
htmlOpts.HTMLEnableSeparatedPages = true;
htmlOpts.HTMLHasPageNavigator = true;
opt.FormatOptions = htmlOpts;
// With HTML the destination options need to be set also.
DiskFileDestinationOptions diskOpts = new DiskFileDestinationOptions ();
diskOpts.DiskFileName = ExportName;
opt.DestinationOptions = diskOpts;
}
break;
case 5: // html 4.0
{
ExportName = GetExportName(Location, false, false, false, true, false);
opt.ExportFormatType = ExportFormatType.HTML40;
HTMLFormatOptions htmlOpts = new HTMLFormatOptions ();
htmlOpts.HTMLFileName = ExportName;
htmlOpts.HTMLEnableSeparatedPages = true;
htmlOpts.HTMLHasPageNavigator = true;
opt.FormatOptions = htmlOpts;
// With HTML the destination options need to be set also.
DiskFileDestinationOptions diskOpts = new DiskFileDestinationOptions ();
diskOpts.DiskFileName = ExportName;
opt.DestinationOptions = diskOpts;
}
break;
}
string cdir = System.IO.Directory.GetCurrentDirectory();
try
{
// make sure I'm sitting in the directory where crystal will
// create the subdirectory containing the html pages
System.IO.Directory.SetCurrentDirectory(Location);
if ((RType == 4) || (RType == 5))
{
// if output directory already exists, then rename it to the
// export output name so the pages can be regenerated
string odname = GetExportName(Location, false, false, true, false, true);
string dname = GetExportName(Location, false, false, true, false, false);
ExportName = GetExportName(Location, false, false, false, true, false);
if (System.IO.Directory.Exists(odname) == true)
System.IO.Directory.Move(odname, dname);
MyReport.ExportToDisk(opt.ExportFormatType, ExportName);
// rename directory to unique name (<name> - <datestamp>) in
// case more exports are desired
dname = GetExportName(Location, false, false, true, false, true);
odname = GetExportName(Location, true, true, false, false, false);
System.IO.Directory.Move(odname, dname);
}
else
MyReport.ExportToDisk(opt.ExportFormatType, ExportName);
}
catch( System.Exception err )
{
// check specifically for the report that causes crystal to give an
// error whenever I export to html. This report exports fine if exporting
// to other non html formats.
if (((RType == 4) || (RType == 5)) && (ExportName == "Drop Report.htm"))
MessageBox.Show("Unable to export Drop Report in the html format. Please choose a different export file format.",
"Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
else
MessageBox.Show( "Error exporting report: " + err.Message.ToString(),
"Export Error!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
System.IO.Directory.SetCurrentDirectory(cdir);
:
:
C#.NET
Crystal Reports.NET
Windows 2K
SQL Server 2000
and am using the following piece of code to automatically setup and export reports to disk files once the report is built. On all 8 current reports, all formats except html export with no problems using this code. It exports to html with no problems on 7 out of 8 reports. However, on one single report, I keep getting the error "Invalid export option" returned by crystal when I try to output to the either html format. The only difference between these reports is that the one that does not export to html has a subreport that gathers information from different tables and outputs to the main report. The other reports do not have such a subreport because all of the work is being done in stored procedures. I would use stored procedures for this one report but SQL does not support arrays and I need certain information arranged this way because the report has a variable number of columns across the page....
:
:
ExportOptions opt = MyReport.ExportOptions;
// drop down control containing available export formats
int RType = ExportFormat.Items.IndexOf(ExportFormat.SelectedItem);
switch( RType )
{
case 0: // adobe
ExportName = GetExportName(Location, false, false, false, false, true);
opt.ExportFormatType = ExportFormatType.PortableDocFormat;
break;
case 1: // excel
ExportName = GetExportName(Location, false, false, false, false, true);
opt.ExportFormatType = ExportFormatType.Excel;
break;
case 2: // word
ExportName = GetExportName(Location, false, false, false, false, true);
opt.ExportFormatType = ExportFormatType.WordForWindows;
break;
case 3: // rich text
ExportName = GetExportName(Location, false, false, false, false, true);
opt.ExportFormatType = ExportFormatType.RichText;
break;
case 4: // html 3.2
{
ExportName = GetExportName(Location, false, false, false, true, false);
opt.ExportFormatType = ExportFormatType.HTML32;
HTMLFormatOptions htmlOpts = new HTMLFormatOptions ();
htmlOpts.HTMLFileName = ExportName;
htmlOpts.HTMLEnableSeparatedPages = true;
htmlOpts.HTMLHasPageNavigator = true;
opt.FormatOptions = htmlOpts;
// With HTML the destination options need to be set also.
DiskFileDestinationOptions diskOpts = new DiskFileDestinationOptions ();
diskOpts.DiskFileName = ExportName;
opt.DestinationOptions = diskOpts;
}
break;
case 5: // html 4.0
{
ExportName = GetExportName(Location, false, false, false, true, false);
opt.ExportFormatType = ExportFormatType.HTML40;
HTMLFormatOptions htmlOpts = new HTMLFormatOptions ();
htmlOpts.HTMLFileName = ExportName;
htmlOpts.HTMLEnableSeparatedPages = true;
htmlOpts.HTMLHasPageNavigator = true;
opt.FormatOptions = htmlOpts;
// With HTML the destination options need to be set also.
DiskFileDestinationOptions diskOpts = new DiskFileDestinationOptions ();
diskOpts.DiskFileName = ExportName;
opt.DestinationOptions = diskOpts;
}
break;
}
string cdir = System.IO.Directory.GetCurrentDirectory();
try
{
// make sure I'm sitting in the directory where crystal will
// create the subdirectory containing the html pages
System.IO.Directory.SetCurrentDirectory(Location);
if ((RType == 4) || (RType == 5))
{
// if output directory already exists, then rename it to the
// export output name so the pages can be regenerated
string odname = GetExportName(Location, false, false, true, false, true);
string dname = GetExportName(Location, false, false, true, false, false);
ExportName = GetExportName(Location, false, false, false, true, false);
if (System.IO.Directory.Exists(odname) == true)
System.IO.Directory.Move(odname, dname);
MyReport.ExportToDisk(opt.ExportFormatType, ExportName);
// rename directory to unique name (<name> - <datestamp>) in
// case more exports are desired
dname = GetExportName(Location, false, false, true, false, true);
odname = GetExportName(Location, true, true, false, false, false);
System.IO.Directory.Move(odname, dname);
}
else
MyReport.ExportToDisk(opt.ExportFormatType, ExportName);
}
catch( System.Exception err )
{
// check specifically for the report that causes crystal to give an
// error whenever I export to html. This report exports fine if exporting
// to other non html formats.
if (((RType == 4) || (RType == 5)) && (ExportName == "Drop Report.htm"))
MessageBox.Show("Unable to export Drop Report in the html format. Please choose a different export file format.",
"Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
else
MessageBox.Show( "Error exporting report: " + err.Message.ToString(),
"Export Error!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
System.IO.Directory.SetCurrentDirectory(cdir);
:
: