2283350 - Exporting to CSV in .NET application and setting the delimiter and separator to nothing defaults to a comma and double quote

SAP Knowledge Base Article - Public

2283350 - Exporting to CSV in .NET application and setting the delimiter and separator to nothing defaults to a comma and double quote

Symptom

In an application that exports to CSV format and setting the Delimiter and separator to an empty string when exporting the defaults are set to a comma and double quote

Environment

Crystal Reports for Visual Studio

Resolution

if (ExportTypeSelected == "crReportExportFormatCharacterSeparatedValues")
#region CSV
{
    // This works do not alter
    // this gets the report name and sets the export name to be the same less the extension
    string outputFileName = "";
    string MyRptName = rpt.FileName.ToString();
    outputFileName = MyRptName.Substring(9, rpt.FileName.Length - 9);
    outputFileName = outputFileName.Substring(0, (outputFileName.Length - 3)) + "csv";
    try
    {
        if (File.Exists(outputFileName))
        {
            File.Delete(outputFileName);
        }

        CrystalDecisions.ReportAppServer.ReportDefModel.CharacterSeparatedValuesExportFormatOptions RasCSVExpOpts = new CharacterSeparatedValuesExportFormatOptions();

        try
        {
            RasCSVExpOpts = rptClientDoc.get_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatCharacterSeparatedValues);
        }
        catch (Exception ex)
        {
            btnSQLStatement.Text = "No Export options saved: " + ex.Message;
            //return;
        }

        // Set them now:
        RasCSVExpOpts.Delimiter = null;
        RasCSVExpOpts.Separator = null;
        //RasCSVExpOpts.ReportSectionsOption

 
        // Save the udpated info
        if (RasCSVExpOpts != null)
            rptClientDoc.set_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatCharacterSeparatedValues, RasCSVExpOpts);

        CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions exportOpts1 = new CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions();
        exportOpts1.ExportFormatType = CrReportExportFormatEnum.crReportExportFormatCharacterSeparatedValues;
        exportOpts1.FormatOptions = RasCSVExpOpts;

        // And Export
        rptClientDoc.PrintOutputController.ExportEx(exportOpts1).Save(outputFileName, true);
        MessageBox.Show("Export to CSV Completed", "", MessageBoxButtons.OK, MessageBoxIcon.Information);

    }
    catch (Exception ex)
    {
        btnSQLStatement.Text = "ERROR: " + ex.Message;
        return;
    }
}
#endregion CSV

Note I am setting both to blank strings or null, either one.

        // Set them now:
        RasCSVExpOpts.Delimiter = null; // ""
        RasCSVExpOpts.Separator = null; // ""

Also tried:

RasCSVExpOpts.Delimiter = string.Empty;

RasCSVExpOpts.Separator = string.Empty;

I all cases through the SDK the default values are the comma and double quotes.

This issue has been escalted to our Developers for a solution in possibly SP 17

Keywords

.net, csv, delimiter, separator , KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , Problem

Product

SAP Crystal Reports, developer version for Microsoft Visual Studio