Binding to a different CSV file

Stimulsoft Reports.WPF discussion
Post Reply
PatrickV
Posts: 13
Joined: Wed Dec 30, 2015 12:59 am

Binding to a different CSV file

Post by PatrickV »

Hi,

I've created a report in the designer (2016.1), based on a CSV file that was located in a given folder and with a givenname.
If I use the following code a PDF is created as expected...

string folder = @"c:\AxyCodeGen\ASR\Export\";
using (StiReport report = new StiReport())
{
// This is the report template that was created using the Designer. Data in there was bases on NotaData160101000005.csv and from within the Designer I can create a
// beautifull report...
report.Load(Path.Combine(folder, "NotaTemplate.mrt"));
report.Render();
report.ExportDocument(StiExportFormat.Pdf, Path.Combine(folder, "OK.Pdf"));
}

What I want to do however is connect the report to a different CSV file (with of course the exact same structure), but I can't get it to work...

using (StiReport report = new StiReport())
{
report.Load(Path.Combine(folder, "NotaTemplate.mrt"));
string newCsvFileName = "NotaDataNew.csv";

// How do I bind My NotaDataNew.CSV file (of course the same structure as the one that the report was created with)?
//....
report.Render();
report.ExportDocument(StiExportFormat.Pdf, Path.Combine(folder, "NewData.Pdf"));
}

Can someone help me with this please?
Thx in advance & kind regards,

Patrick
Jan
Posts: 1265
Joined: Thu Feb 19, 2009 8:19 am

Re: Binding to a different CSV file

Post by Jan »

Hello, Patrick!

You can use following code:

Code: Select all

var report = new StiReport();
report.Load("d:\\report.mrt");
            
var dataBase = report.Dictionary.Databases["CSV1"] as StiCsvDatabase;
//Change path to the csv folder
dataBase.PathData = "D:\\Stimulsoft\\Stimulsoft.Reports\\Reports";

var dataTable = report.Dictionary.DataSources["Sample"] as StiDataStoreSource;
//Change name of the csv file
dataTable.NameInSource = "CSV1.Sample";//CSV1 - its a name of the CSV Connection in the report dictionary, Sample - its a name of the CSV file in the folder

report.ExportDocument(StiExportFormat.Pdf, Path.Combine(folder, "OK.Pdf"));

Please contact us if you need any help.

Thank you.
PatrickV
Posts: 13
Joined: Wed Dec 30, 2015 12:59 am

Re: Binding to a different CSV file

Post by PatrickV »

Hi Jan,

Works like a charm!
Thx very much!!!

Patrick
Jan
Posts: 1265
Joined: Thu Feb 19, 2009 8:19 am

Re: Binding to a different CSV file

Post by Jan »

Hello, Patrick!

You are welcome!
Post Reply