Telerik Reporting R1 2017

Connecting the CsvDataSource Component to a CSV Source

When you configure the CsvDataSource component the settings below are obligatory to avoid runtime error due to failed data retrieval:

  • Source - Specifies the CSV document which will be used by using the Uri class or an inline string. If set to null an exception is thrown;

  • Field separators - Configures the list of separators by which the document will be split to fields (columns) based on a delimiter;

  • Record separators - Configures the list of separators by which the document will be split to records (rows) based on a delimiter.

Optional settings for the proper functioning of the CsvDastaSource you need to consider:

  • Has headers - configures if the CSV source has a header row, by default is false;

  • Escape format - for more information please check CsvDataSource Escape Formats; default value is None;

  • Quote - if the Escape format is Quotes or Quotes Mixed then the Quote property must be set.

var csvDataSource = new CsvDataSource();
csvDataSource.Source = new Uri(@"C:\temp\MyCsvDocument.csv");
csvDataSource.FieldSeparators = new[] { ',' };
csvDataSource.RecordSeparators = new[] { '\r', '\n' };
csvDataSource.HasHeaders = false;
csvDataSource.EscapeFormat = CsvEscapeFormat.Quotes;
csvDataSource.Quote = '"';

Optional setting:

csvDataSource.ConsecutiveFieldSeparatorsAsOne = false;
csvDataSource.ConsecutiveRecordSeparatorsAsOne = true;
csvDataSource.CommentToken = '#';
csvDataSource.DecimalSeparator = ".";
csvDataSource.ThousandSeparator = " ";
csvDataSource.DateTimeFormat = "MM/dd/yyyy hh:mm";