Execute SSRS report from C#

Hi All,

I need urgent Advise/help. I am working on Project. Let me try to explain. My Company is using Application (C# UI). My requirement is.

For E.g My SSRS Report, Parameters are (@EmployeeFName, @EmployeeLName, @Department)
So in Application, I create a form with three fields where User will Enter @EmployeeFName, @EmployeeLName, @Department and Hit Submit. Once User Hit Submit I want to Execute SSRS report and it is up to the user if they want to just review the report or save into Excel.

Please guide me how can I accomplish this Project. Please let me know if my question is not clear. Any advice would be great appreciated.

This is very easy to do. You have a few options for calling the report like using the URL or web service. For the URL, it can be as simple as calling a function that builds the URL based on the parameters.

Below is a function that would be called when one of the parameter options changed on an ASP.Net c# page.

Once the URL is built and the user clicks on it, it opens the SSRS report in the report manager where the user can then export the report if they want to any of the supported formats.

Very basic and easy to do.

private void formatURL()
{
startdate = "&rs:Command=Render&startdate=" +
Calendar1.SelectedDate.ToShortDateString();
enddate = "&rs:Command=Render&enddate=" +
Calendar2.SelectedDate.ToShortDateString();
if (DropDownList2.SelectedValue.ToString() != "Nothing")
{
strOrderStatus = "&rs:Command=Render&OrderStatusId=" +
DropDownList2.SelectedValue.ToString();
}

HyperLink1.NavigateUrl = "http://<YourServer>/reportserver?/<Your 

Report Folder>/&rs:Command=Render&rc:zoom=Page
Width&rc:parameters=false&rc:toolbar=true&rc:docmap=false&rs:Format=HTML4.0" +
startdate + enddate + strOrderStatus;
}

1 Like

Hi James,

Thank You for your response. I am not good in C#. I have few questions and Please correct me if I am wrong.

  1. In above C# code, Startdate, Enddate, StrOrderStatus are your Parameters in SSRS Report, right?
  2. How can I pass my Parameters from C# Form that user will Enter through UI?

Once again thank you for your help.

The parameters as defined in the SSRS report are named:
startdate
enddate
OrderStatusId

The URL building piece consists of string variables to make it easier to work with. You can do it so many different ways and this was something that I put together more than 12 years ago so it's dated and may not be the most up-to-date way of doing it.

But like my mom used to say about me, it's ugly but it works.

Here are a few reference links that may help you.

SSRS URL Access Parameter Reference

Pass a Report Parameter Within a URL

The most important thing is how you call the report and pass in the parameters for your needs. URL access may not be the most secure for you and web service would be better.

1 Like

Thank You James, once again for your help. I will try this with URL. By chance do you any sample code with Web Service instead of URL?

You are welcome. Glad I can help.

I don't have any examples for using the web service from previous work I have done. Also, what I did do previously was from much older versions of SSRS and may not be applicable to what you want to do. There are lots of better up-to-date examples online and I would encourage you to search for those.

If I can help further please let me know.

Thank You James. If I face any issue I will message you.

James, I need your help. Could you please check your IM. I emailed you few days back.

Thanks for reply in advance.