[quoted text, click to view] On Oct 25, 5:34 pm, "IfThenElse" <sql_agent...@hotmail.com> wrote:
> Hi,
>
> I have a report with parameters and need to get it via C# in PDF Format.
>
> Need an example that works.
>
> Thank you,
Here's an example. It's a snippet from a web method I wrote to call
and export an SSRS report programmatically. In this example, I
declared a web reference named 'SSRSExecutionSvc' that points to the
report server's wsdl file.
Byte[] result = null;
String strReportPath = "", strFormat = "", strDeviceInfo =
"", strEncoding = "",
strMimeType = "", strExt = "", strSessionId = "",
strInvoicePath = "";
String strHistoryID = null;
String[] strStreamIDs = null;
strInvoicePath =
ConfigurationManager.AppSettings["InvoicePath"].ToString();
SSRSExecutionSvc.ReportExecutionService rs = new
SSRSExecutionSvc.ReportExecutionService();
//If you explicitly define a user below instead of the
default used here, you will need to make sure that the user account
has, at a minimum, Browser rights in the Report Manager.
rs.Credentials =
System.Net.CredentialCache.DefaultCredentials;
rs.Url = "http://ServerName/reportserver/
ReportExecution2005.asmx";
// Render arguments
strReportPath = "/Reports Directory/ReportName";
strFormat = "PDF";
strDeviceInfo = @"<DeviceInfo><Toolbar>False</Toolbar></
DeviceInfo>";
// Prepare report parameter.
SSRSExecutionSvc.ParameterValue[] parameters = new
SSRSExecutionSvc.ParameterValue[1];
parameters[0] = new SSRSExecutionSvc.ParameterValue();
parameters[0].Name = "ORDERID";
parameters[0].Value = OrderID.ToString();
SSRSExecutionSvc.Warning[] warnings = null;
SSRSExecutionSvc.ExecutionInfo execInfo = new
SSRSExecutionSvc.ExecutionInfo();
SSRSExecutionSvc.ExecutionHeader execHeader = new
SSRSExecutionSvc.ExecutionHeader();
rs.ExecutionHeaderValue = execHeader;
execInfo = rs.LoadReport(strReportPath, strHistoryID);
rs.SetExecutionParameters(parameters, "en-us");
strSessionId = rs.ExecutionHeaderValue.ExecutionID;
try
{
result = rs.Render(strFormat, strDeviceInfo, out
strExt, out strEncoding, out strMimeType, out warnings, out
strStreamIDs);
execInfo = rs.GetExecutionInfo();
}
catch (SoapException SoapEx)
{
return SoapEx.Detail.OuterXml.ToString();
}
// Write the Contents of the Invoice to a PDF Document.
try
{
FileStream stream = File.Create((strInvoicePath +
"Order " + OrderID.ToString() + " Invoice.pdf"), result.Length);
stream.Write(result, 0, result.Length);
stream.Close();
}
catch (Exception Ex)
{
return Ex.Message;
}
This was created in C# 2005 (ASP.NET 2.0) as a Web Method for SSRS
2005. I'm not sure if this functionality is also available in SSRS
2000; however, it's worth a try. Hope this helps.
Regards,
Enrique Martinez
Sr. Software Consultant