Skip to Content
0
Dec 18, 2018 at 06:20 PM

ASP.NET CrystalReportViewer CSV Options

164 Views

Hello. I am using CrystalDecisions v13.0.2000.0 in an ASP.NET webforms site and I am using the CrystalReportViewer. The report has parameters and everything works perfectly when displaying the report in the web page. The user needs to be able to export to CSV and the built-in export button works but it includes the column names in every row and a secondary dialog is not presented to be able to specify additional options. I need to specify ReportSectionsOption = CsvExportSectionsOption.ExportIsolated. It seemed the solution was to write the report using ExportToHttpResponse on postback but all I get is the "Please wait while the document is being processed" message. Here is my code:

ReportInfo ri = Session[ReportName] as ReportInfo;
if (ri == null) return;
if (ReportName == "policies" && IsPostBack)
{
    ReportDocument rd = ri.ReportDocument;
    foreach (ParameterField pf in CrystalReportViewer1.ParameterFieldInfo)
    {
        if (pf.ReportName == "") rd.SetParameterValue(pf.Name, pf.CurrentValues);
        else rd.SetParameterValue(pf.Name, pf.CurrentValues, pf.ReportName);
    }
    CharacterSeparatedValuesFormatOptions csveo = new CharacterSeparatedValuesFormatOptions();
    csveo.Delimiter = "\"";
    csveo.SeparatorText = ",";
    csveo.GroupSectionsOption = CsvExportSectionsOption.DoNotExport;
    csveo.ReportSectionsOption = CsvExportSectionsOption.ExportIsolated;
    csveo.ExportMode = CsvExportMode.Standard;


    ExportOptions eo = new ExportOptions() { ExportFormatType = ExportFormatType.CharacterSeparatedValues, ExportFormatOptions = csveo };
    rd.ExportToHttpResponse(eo, Response, true, "policies.csv");
}
else CrystalReportViewer1.ReportSource = ri.ReportDocument;

What am I doing wrong? Also, oddly, the parameters that I enter in the report viewer are not set in the ParameterFieldInfo on postback. Where are these values?

Thanks.