Fork me on GitHub
2sxc 9.0 for DNN 7 to 9
Website Builder, Content Manager, App-System: free and amazing - done your way
You are here: Home  >  Docs  >  Feature

CsvDataSource to read and publish CSV Files

Introduced in Version 07.02.00

A data source which will deliver CSV data (comma separated values) to your templates, razor, tokens or WebAPI / JSON. 

 

This is what it looks like in the Visual Query Designer

 

Streams in the CsvDataSource DataSource

  • In - non expected
    • It expects no In-Streams. If you add any, you could use that for parameters, but this is an uncommon scenario
  • Out - Default only
    • Default - containing the list of items in the CSV file

Configuration of the CsvDataSource

  1. File Path - a path based on the root of the web-server, like /Portals/0/Sync/MyProducts.csv or /App_Data/Sync/ERP-Export.csv
  2. Delimiter - this can be a comma, semi-colon, tab or anything. If you want to add a tab, best create one using Microsoft-Word and copy-paste it into the field. You can also leave this blank, then a tab will be assumed. 
  3. Content-Type Name - an internal name like "CsvProducts" or something - not relevant for most use cases
  4. Id-Column Name - leave blank to auto-number each item based on the CSV-rows; if you have a number-field which marks each item in the CSV like PRODUCTID or something, I would use that. Note that it's case sensitive. 
  5. Title-Field Name - the title field. Leave blank to just use the first column in your CSV if you don't care about the exact field. Case sensitive. 

Note that in all these cases you can also use Tokens for parameters. For example

  • you could say the file should be /App_Data/Sync/[DateTime:Now|yyyy-mm]/export.csv to use year-month in your path. 
  • you could also place the file in App-Settings so that your editor can change it - then your file would just come from [App:Settings:ProductSyncFile] or similar

Special Behavior of the CsvDataSource

CSV is one of the oldest file formats - but it still is not fully standardized. We're using a CSV Framework called CSVHelper for this job which takes care of many things, but we're assuming each value is a string-value to prevent too many bugs when reading the CSV file. So you'll probably want to do some re-formating in your template for dates and similar stuff.  

 

Tags for this feature

2serve . 2invent . 2create is 2be.