Hi,
I am trying to programatically export a report based on the documentation. The following code works when a connection string is set in my config file, but I'm wondering how I can set the connection string at run time (and set any report parameters) before calling export?
static void Main(string[] args) { var uri = new Uri("InfragisiticsReportingTrial.Reports;component/SalesReport.igr", UriKind.Relative); using (var exporter = ServerExporterFactory.CreateExporter(uri)) { using (var fs = new System.IO.FileStream(@"c:\temp\igsalesreport.pdf", FileMode.Create)) { exporter.Export(fs, "PDF"); } } }
Hi Joe,
The exporter object exposes the Parameters and DataSources properties to allow users to set parameters and override the data sources used by the report.
You may refer to the IServerExporter interface documentation for more details.
Let us know if you have any additional questions.
Regards,Héctor
I was able to do this by implementing IReportDbConnectionProvider (below). But that just leads to more questions
1. Can I access the Sql stored in the report and update it on the fly?
2. IServerExporter.DataSources - is there an example of adding one?
3. IServerExporter.Parameters - again, is thaere an example of this being used? Google is failing me.
Thanks
Joe
[ReportDbConnectionExport(ReportSearchPattern = ".*")] public class ConnectionProvider : IReportDbConnectionProvider { public DbConnection GetConnection(string name, IDictionary<string, ParameterValue> reportParameters) { return new SqlConnection(@"Data Source=myserver;Initial Catalog=Northwind;User ID=myuser;Password=mypassword"); } }