Skip to main content
A newer version of this page is available. .

Bind a Report to a CSV File (Runtime Sample)

  • 5 minutes to read

This example demonstrates how to bind a report to a CSV file and specify the report layout at runtime.

Do the following to bind a report to a CSV file:

  1. Create the ExcelDataSource class’s instance and specify the full path to the source file by setting its ExcelDataSource.FileName property.
  2. Create the CsvSourceOptions class’s instance to specify the required import settings.

    Enable the CsvSourceOptions.DetectEncoding, CsvSourceOptions.DetectNewlineType and CsvSourceOptions.DetectValueSeparator options to automatically determine the character encoding, the line break type and a character that separates values in the source CSV document.

    Assign the created CsvSourceOptions object to the ExcelDataSource.SourceOptions property.

  3. The report engine automatically generates a data source schema by default. Do the following to manually define the data source schema if you need to customize the data fields’ display names and types:

  4. Assign the created data source to the report’s XtraReportBase.DataSource property.
  5. Provide data to report controls using the XRControl.ExpressionBindings or XRControl.DataBindings property depending on the report’s data binding mode.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace BindingReportToCsvFile
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            //Uncomment this line to switch to the legacy binding mode.  
            //DevExpress.XtraReports.Configuration.Settings.Default.UserDesignerOptions.DataBindingMode =
            //    DevExpress.XtraReports.UI.DataBindingMode.Bindings;
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}
See Also