I am working on a solution that uses Report Viewer to access SSRS reports in our server. Currently the server URL and the repot path, are values stored in the Web.config file.
Web.config
<add key="ReportServerUrl" value="https://sqlssrs/reportserver"/>
<add key="ReportPath" value="/group/type/report-name"/>
Then these values are mapped in the ReportViewer.aspx.cs code behind.
ReportViewer.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
try
{
// Add the Reporting Server URL
rvSiteMapping.ServerReport.ReportServerUrl = new Uri(ConfigurationManager.AppSettings["ReportServerUrl"].ToString());
//Add the Report Path
rvSiteMapping.ServerReport.ReportPath = ConfigurationManager.AppSettings["ReportPath"].ToString();
rvSiteMapping.ServerReport.Refresh();
}
catch (Exception)
{
}
}
}
I was asked to try to make a change that will allows us to pass the Report Path value, as a query string parameter.
I am not sure how to accomplish this task. I tried to do the following.
rvSiteMapping.ServerReport.ReportServerUrl = new Uri("http://sqlssrs/reportserver?pReportPath=/group/type/report-name");
rvSiteMapping.ServerReport.ReportPath= HttpUtility.ParseQueryString(rvSiteMapping.ServerReport.ReportServerUrl).Get("pReportPath");
That code does not work. It gives me an error that reads.
Error CS1503 Argument 1: cannot convert from 'System.Uri' to 'string'
Would it be possible to get some instruction on how to be able to accomplish this task? I am running the report within Visual Studio 2015, I am thinking I also need to set the URL in the project configuration, but I am not sure about that either.
I appreciate any direction on how to program this, any articles, examples, whatever can aid me to complete this task.
Thank you for sharing your experience.
Erasmo
You can use Request.QueryString["pReportPath"]
to retrieve the query value.
Try:
// Add the Reporting Server URL
rvSiteMapping.ServerReport.ReportServerUrl = new Uri(ConfigurationManager.AppSettings["ReportServerUrl"].ToString());
//Add the Report Path
rvSiteMapping.ServerReport.ReportPath = Request.QueryString["pReportPath"];
Then navigate your browser to ReportViewer.aspx?pReportPath=/group/type/report-name