This is a migrated thread and some comments may be shown as answers.

Can't pass parameters to report during programmatic export

1 Answer 115 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 2
Chris asked on 11 Apr 2013, 12:52 PM
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:
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


1 Answer, 1 is accepted

Sort by
0
Chris
Top achievements
Rank 2
answered on 11 Apr 2013, 02:58 PM
False alarm - I am a complete idiot, I switch the input parameters on the method call.

Sorry :-(

Chris
Tags
General Discussions
Asked by
Chris
Top achievements
Rank 2
Answers by
Chris
Top achievements
Rank 2
Share this question
or