CodeMonkey1313
CodeMonkey1313

Reputation: 16011

ASP.NET ReportViewer Server Report Render Stream results in exception

I'm trying to use the ServerReport.RenderStream method from the ASP.NET ReportViewer (2008 SP1), but I'm getting a rsStreamNotFound exception from the method. I've tried the two different lines of code below after setting the parameters. I'm interfacing with SQL Server 2005 and SSRS 2005. I've seen articles about a hotfix for this issue, but I'd really rather not resort to a hotfix, as I'm not sure that IT will be OK with it going in. There isn't too much documentation that I've found on the error which is

The stream cannot be found. The stream identifier that is provided to an operation cannot be located in the report server database.report server database.

Prep Code:

string mimeType;
string encoding;
List<ReportParameter> parameters = new List<ReportParameter>();
string startDateValue = Request.Form[startDate.UniqueID];

string endDateValue = Request.Form[endDate.UniqueID];
parameters.Add(new ReportParameter("Owner", "5", false));
parameters.Add(new ReportParameter("StartDate", startDateValue, false));
parameters.Add(new ReportParameter("EndDate", endDateValue, false));
ReportViewer1.ServerReport.SetParameters(parameters);

Call 1:

byte[] result = ReportViewer1.ServerReport.RenderStream("PDF", string.Empty, string.Empty, out mimeType, out encoding);

Call 2:

byte[] result = ReportViewer1.ServerReport.RenderStream("CSV", string.Empty, string.Empty, out mimeType, out encoding);

Clean up:

Response.Clear();
Response.ContentType = mimeType;
Response.ContentEncoding = System.Text.Encoding.GetEncoding(encoding);
Response.OutputStream.Write(result, 0, result.Length);

Any thoughts on a solution? The end goal is to write this out to CSV for a download. In reality I'd be happy with XML that I'd translate to CSV.report server database.

Upvotes: 0

Views: 5465

Answers (2)

Kodithic
Kodithic

Reputation: 170

RenderStream is used to take an existing Stream and process it in a different manner or render external resources, so Render was what you needed all along. The C# signature of RenderStream is

public byte[] RenderStream (
    string format,
    string streamId, //cannot be String.Empty!
    string deviceInfo,
    out string mimeType,
    out string encoding
)

The second parameter, streamId, is the ID of an existing Stream; you were passing String.Empty, hence the error message of not finding the identifier. You can get the StreamID(s) with out string[] streams from one of the Render() methods:

public override byte[] Render (
    string format,
    string deviceInfo,
    out string mimeType,
    out string encoding,
    out string fileNameExtension,
    out string[] streams, //"The stream identifiers. You can use them to render external resources (images, for example) that are associated with the report."
    out Warning[] warnings
)

This question deals more with using Render and RenderStream.

(I realize the question is a year old, but I thought I'd post what I found for anyone else who stumbles upon it.)

Upvotes: 2

CodeMonkey1313
CodeMonkey1313

Reputation: 16011

Yep, the Render method does exactly what I want it to do. I'd love to hear from someone that has experience on RenderStream though.

Upvotes: 0

Related Questions