Legion
Legion

Reputation: 3447

How do you send an array of parameter values to SSRS via HTTP Post?

I'm trying to get SSRS to generate reports in PDF format and capture the byte stream to save them to disk. This works fine if the only report parameters I have to send are single values, but if I have to send an array of values for a particular parameter it no longer works.

The below works fine because I'm only sending one Year value. Via the UI, the Year parameter would be a multiselect.

        string parameters = "rs:Command=Render&rs:format=PDF&Year=2018"
        byte[] paramHeader = Encoding.ASCII.GetBytes(parameters);
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(URL);
        req.PreAuthenticate = true;
        req.Credentials = new System.Net.NetworkCredential(
            reportUser,
            reportUserPW,
            reportUserDomain);

        req.Method = "POST";
        req.ContentType = "application/x-www-form-urlencoded";
        req.ContentLength = paramHeader.Length;

        using (var stream = req.GetRequestStream())
        {
            stream.Write(paramHeader, 0, paramHeader.Length);
        }

            HttpWebResponse HttpWResp = (HttpWebResponse)req.GetResponse();
            Stream fStream = HttpWResp.GetResponseStream();
            File.WriteAllBytes(JobId.ToString() + "\\employeeName.pdf", copyStreamToByteArray(fStream));

If I change the parameters string to have multiple Year values it fails:

string parameters = "rs:Command=Render&rs:format=PDF&Year=2018,2017,2016"

I tried looking at the web traffic when using the Reports Services UI to see how it sends parameters to SSRS with Fiddler but couldn't get any useful information out of it. It looked like it'd been encoded in a ViewState string of some kind.

How can I send an array of values for a given SSRS parameter in a Post header?

Upvotes: 0

Views: 895

Answers (1)

Wolfgang Kais
Wolfgang Kais

Reputation: 4100

To make this work, simply repeat the parameter for each additional value like this:

string parameters = "rs:Command=Render&rs:format=PDF&Year=2018&Year=2017&Year=2016"

Upvotes: 2

Related Questions