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"); } }
1. No, that is not possible. The idea is to either use the DataSources property, or use the DB connection provider to override the connection details.
2., 3. There are no online examples, but the properties are straightfoward to use:
var uri = new Uri("ProgrammaticExportWithRuntimeDataSources;component/Report1.igr", UriKind.Relative);
using (var exporter = ServerExporterFactory.CreateExporter(uri))
{
using (var fs = new System.IO.FileStream(@"c:\temp\igsalesreport.pdf"))
var dataSources = new List();
dataSources.Add(
new DataSourceValue
Name = "Data Source Name",
Value = /* IEnumerable that contains the data */
});
exporter.DataSources = dataSources;
var parameters = new List();
parameters.Add(
new ParameterValue
Name = "Parameter Name",
Value = /* Parameter Value */
exporter.Parameters = parameters;
exporter.Export(fs, "PDF");
}
I got it to Work with help of this page
http://es.infragistics.com/help/topic/083A71E2-7382-494C-A044-BF4BA0DAB59D
I have a problem with exporting to PDF on the serverWhen I run it on my local machine it worksbut when I deploy it to the web server I this error
Exception information:
Exception type: ReportProcessorException
Exception message: An error occurred while processing the Report.
at Infragistics.Reports.Server.ServerExporter.Export(Stream output, String exportFormat)
at Intranet.Opret3.Dan_PDF2(String Filnavn, Int32 ID)
at Intranet.Opret3.btn_Gem_OnClick(Object sender, EventArgs e)
at System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e)
at System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Object reference not set to an instance of an object.
at Infragistics.Reports.Engine.ServiceModelMefDiscoverer.Initialize(IServiceModelManager serviceModel)
at Infragistics.Reports.Engine.ServiceModelBuilder.Setup(IServiceModelConfiguration configuration)
at Infragistics.Reports.Server.ServerExporter.CreateLocalEngine(IEnumerable`1 dataSources, IReportInstanceSession& session)
Dim reportUri = New Uri("/Arrangement/Arr_Bekraeft.igr", UriKind.Relative)Dim Exporter = ServerExporterFactory.CreateExporter(reportUri)Dim Param As New List(Of Infragistics.Reports.ParameterValue)Dim P1 As New Infragistics.Reports.ParameterValue()P1.Name = "ID"P1.Value = IDParam.Add(P1)Exporter.Parameters = ParamDim FilStream As New FileStream(Filnavn, FileMode.Create)Exporter.Export(FilStream, "PDF")FilStream.Close()
Thanks, Hector.