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. Use the XRControl.ExpressionBindings property to provide data to the report.
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>
        static void Main()
            Application.Run(new Form1());
See Also