Hi,
I am am trying to export a report programmatically to then attach to an email. The report runs correctly and is save as expected, I just cannot get the parameter values to pass through to the report, I have followed the advice in the following two articles:
The report being used is used elsewhere in the website in a ReportViewer control wheer it's parameters are set prgramatically and it works correctly.
This is the code I am using is below:
Do you have any ideas as to why my reports is not receiving the parameters as passed to it. This code is setting the parameters via code but using a ReportViewer to see the result, this works as expected.
I am using Q3 2012 (6.2.12.1017) in an ASP.NET 4 website.
Thanks
Chris
I am am trying to export a report programmatically to then attach to an email. The report runs correctly and is save as expected, I just cannot get the parameter values to pass through to the report, I have followed the advice in the following two articles:
- Exporting Report Programatically
- InstanceReportSource class - this shows how to add initial parameter values
The report being used is used elsewhere in the website in a ReportViewer control wheer it's parameters are set prgramatically and it works correctly.
This is the code I am using is below:
public
static
string
ExportToPdf(
string
documentName,
int
periodId,
int
pupilId)
{
ReportProcessor reportProcessor =
new
ReportProcessor();
Hashtable deviceInfo =
new
Hashtable();
InstanceReportSource instanceReportSource =
new
InstanceReportSource ();
instanceReportSource.ReportDocument=
new
ARView2();
instanceReportSource.ReportDocument.DocumentName = documentName;
instanceReportSource.Parameters.Add(
new
Telerik.Reporting.Parameter(
"PeriodID"
, periodId));
instanceReportSource.Parameters.Add(
new
Telerik.Reporting.Parameter(
"PupilID"
, pupilId));
RenderingResult result = reportProcessor.RenderReport(
"PDF"
, instanceReportSource, deviceInfo);
string
fileName = result.DocumentName +
"."
+ result.Extension;
string
filePath = Path.Combine(Path.GetTempPath(), fileName);
using
(FileStream fs =
new
FileStream(filePath, FileMode.Create))
{
fs.Write(result.DocumentBytes,0,result.DocumentBytes.Length);
}
return
filePath;
}
Do you have any ideas as to why my reports is not receiving the parameters as passed to it. This code is setting the parameters via code but using a ReportViewer to see the result, this works as expected.
if
(e.Item.Level == 0)
return
;
string
[] parms = e.Item.Value.Split(
':'
);
int
periodId = Convert.ToInt32(parms[0]);
int
pupilId = Convert.ToInt32(parms[1]);
var rpt =
new
ARView2
{
DocumentName =
string
.Format(
"{0} {1} {2}"
,cbPermittedPupils.Text.Trim().Replace(
","
,
""
),
pbARList.SelectedItem.Text.Trim(),
((RadPanelItem)pbARList.SelectedItem.Parent).Text)
};
rvAR.ReportSource =
new
InstanceReportSource { ReportDocument = rpt };
rvAR.ReportSource.Parameters.Add(
new
Parameter(
"PeriodID"
, periodId));
rvAR.ReportSource.Parameters.Add(
new
Parameter(
"PupilID"
, pupilId));
rvAR.RefreshReport();
I am using Q3 2012 (6.2.12.1017) in an ASP.NET 4 website.
Thanks
Chris