Hello,
Currently I'm using Telerik Reporting as internal rendering process of file request. During initialization in MVC application I have following code:
So as you can see I render file and return it normaly as MVC File
I'm also changing internal connection string because the same report can run against different databases:
My question now is how to use report generated by line:
in HTML5 MVC application?
I cannot find any example how to use such automatic report in new functionality.
Could you help me?
Currently I'm using Telerik Reporting as internal rendering process of file request. During initialization in MVC application I have following code:
var reportDefinitionFile = Path.Combine(dataFolder, company, "Notice.trdx");
if (!System.IO.File.Exists(reportDefinitionFile))
{
throw new HttpException((int)HttpStatusCode.NotFound, "File not found.");
}
var xmlSerializer = new ReportXmlSerializer();
var reportDocument = (Report)xmlSerializer.Deserialize(reportDefinitionFile);
reportDocument.ReportParameters["ContactId"].Value = n.ToString("D");
var sds = (SqlDataSource)reportDocument.DataSource;
sds.ConnectionString = database.ConnectionString;
this.SetConnectionString(reportDocument.Items, database.ConnectionString);
// create a ReportSource object
var reportSource = new InstanceReportSource { ReportDocument = reportDocument };
var reportProcessor = new ReportProcessor();
RenderingResult result = reportProcessor.RenderReport("PDF", reportSource, null);
return File(result.DocumentBytes, "application/pdf", "File.pdf");
private void SetConnectionString(IEnumerable<
ReportItemBase
> items, string connectionString)
{
foreach (ReportItemBase ib in items)
{
if (ib.Items != null)
{
this.SetConnectionString(ib.Items, connectionString);
}
Type type = ib.GetType();
PropertyInfo dataSourceProperty = type.GetProperty("DataSource");
if (dataSourceProperty == null)
{
continue;
}
var dataSource = dataSourceProperty.GetValue(ib, null) as System.Web.UI.WebControls.SqlDataSource;
if (dataSource != null)
{
dataSource.ConnectionString = connectionString;
}
}
}
My question now is how to use report generated by line:
var reportSource = new InstanceReportSource { ReportDocument = reportDocument };
I cannot find any example how to use such automatic report in new functionality.
Could you help me?