Table of Contents

Class CsvDataProvider

Namespace
combit.Reporting.DataProviders
Assembly
combit.ListLabel31.CrossPlatform.dll

Provides data from CSV (Comma-Separated Values) files.

[Serializable]
public sealed class CsvDataProvider : IDataProvider, IDisposable, ISerializable
Inheritance
CsvDataProvider
Implements
Inherited Members

Examples

The following example demonstrates how to use the CsvDataProvider to export a report to PDF:

// Create a CsvDataProvider from a CSV file with headers.
CsvDataProvider provider = new CsvDataProvider(
    @"C:\Data\customers.csv",
    firstLineIsHeader: true,
    tableName: "Customers",
    separator: ',',
    linesToSkip: 0,
    supportsCount: true);

// Optional: Configure encoding for non-ASCII characters.
// provider.ContentEncoding = Encoding.UTF8;

// Optional: Allow newlines in quoted fields.
// provider.IsNewLineAllowedInQuotedField = true;

// Create a ListLabel reporting engine instance and assign the provider as the data source.
using ListLabel listLabel = new ListLabel();
listLabel.DataSource = provider;

// Configure export settings to generate a PDF.
ExportConfiguration exportConfiguration = new ExportConfiguration(LlExportTarget.Pdf, exportFilePath, projectFilePath);
exportConfiguration.ShowResult = true;

// Export the report to PDF.
listLabel.Export(exportConfiguration);

Remarks

The CsvDataProvider class implements IDataProvider, IDisposable, ISerializable, and combit.Reporting.DataProviders.ISupportsParameters to enable reading data from CSV files or streams. It supports both file-based and stream-based CSV data sources with extensive configuration options including custom field separators, framing characters (quotes), header row detection, line skipping, and encoding selection. The provider can handle quoted fields containing special characters and optionally allows newlines within quoted fields. It also supports parameter binding for dynamic file paths, making it suitable for scenarios where the CSV file location needs to change based on report parameters. The provider creates a single table from the CSV data, with column names derived from the first row (if configured) or auto-generated.

Constructors

CsvDataProvider(Stream, bool, string, char, int, bool)

Initializes a new instance of the CsvDataProvider class using a stream.

public CsvDataProvider(Stream stream, bool firstLineIsHeader = true, string tableName = "", char separator = ',', int linesToSkip = 0, bool supportsCount = true)

Parameters

stream Stream

The stream containing CSV data.

firstLineIsHeader bool

A value indicating whether the first line of the CSV contains header information.

tableName string

The name of the table to be created from the CSV data.

separator char

The field separator character.

linesToSkip int

The number of initial lines to skip in the CSV data.

supportsCount bool

A value indicating whether row count is supported.

CsvDataProvider(string, bool, string, char, int, bool, ProvideFileName?)

Initializes a new instance of the CsvDataProvider class using a file name.

public CsvDataProvider(string fileName, bool firstLineIsHeader = true, string tableName = "", char separator = ',', int linesToSkip = 0, bool supportsCount = true, CsvDataProvider.ProvideFileName? provideFileName = null)

Parameters

fileName string

The file name of the CSV data source.

firstLineIsHeader bool

A value indicating whether the first line of the CSV contains header information.

tableName string

The name of the table to be created from the CSV data.

separator char

The field separator character.

linesToSkip int

The number of initial lines to skip in the CSV data.

supportsCount bool

A value indicating whether row count is supported.

provideFileName CsvDataProvider.ProvideFileName

An optional delegate to process or override the file name.

Exceptions

ListLabelException

Thrown if parameter bindings are used and the table name is not provided.

Properties

ContentEncoding

Gets or sets the content encoding used when reading the CSV data.

public Encoding ContentEncoding { get; set; }

Property Value

Encoding

FileName

Gets or the file name of the CSV data source.

public string FileName { get; }

Property Value

string

FirstLineIsHeader

Gets or sets a value indicating whether the first line of the CSV contains header information.

public bool FirstLineIsHeader { get; set; }

Property Value

bool

FramingCharacter

Gets or sets the framing (or quote) character used in the CSV.

public char FramingCharacter { get; set; }

Property Value

char

IsNewLineAllowedInQuotedField

Gets or sets a value indicating whether a new line is allowed in a quoted field.

public bool IsNewLineAllowedInQuotedField { get; set; }

Property Value

bool

LinesToSkip

Gets or sets the number of lines to skip at the beginning of the CSV file.

public int LinesToSkip { get; set; }

Property Value

int

Separator

Gets or sets the character used to separate fields in the CSV.

public char Separator { get; set; }

Property Value

char

SupportsCount

Gets or sets a value indicating whether counting the number of rows is supported.

public bool SupportsCount { get; set; }

Property Value

bool

TableName

Gets or sets the table name for the CSV data.

public string TableName { get; set; }

Property Value

string

Methods

Dispose()

Releases all resources used by the CsvDataProvider.

public void Dispose()

~CsvDataProvider()

Finalizes an instance of the CsvDataProvider class.

protected ~CsvDataProvider()