Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to Programatically get a Report in PDF format from SSRS

111 views
Skip to first unread message

IfThenElse

unread,
Oct 25, 2007, 6:34:05 PM10/25/07
to
Hi,

I have a report with parameters and need to get it via C# in PDF Format.

Need an example that works.

Thank you,

IfThenElse

unread,
Oct 25, 2007, 6:37:04 PM10/25/07
to
In Addition I am using SQL 2000 NOT 2005


"IfThenElse" <sql_ag...@hotmail.com> wrote in message
news:OsNukc1F...@TK2MSFTNGP06.phx.gbl...

Norman Yuan

unread,
Oct 25, 2007, 7:29:51 PM10/25/07
to
Call Reporting Services' web services. There is a method called Render(),
that returns report in certain formt (PDF,HTML...) as binary stream. Simply
save the sttream to disk or send it back to user's browser (if the calls is
made via web application).


"IfThenElse" <sql_ag...@hotmail.com> wrote in message

news:ejZ3Pe1F...@TK2MSFTNGP02.phx.gbl...

EMartinez

unread,
Oct 25, 2007, 9:17:00 PM10/25/07
to


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

Bruce L-C [MVP]

unread,
Oct 26, 2007, 9:40:50 AM10/26/07
to
Several sent posts to you about webservices. The other option is to embed an
IE control and then use URL integration (you just create the appropriate URL
string and set the property on the IE control). Search Books Online on the
web (RS 2000 books on line does not have as good a set of documentation on
URL integration as 2005 - url integration is the same for both versions so
the RS 2005 documentation will work for you).

With URL integration you have full control over the rendering format.


--
Bruce Loehle-Conger
MVP SQL Server Reporting Services


"IfThenElse" <sql_ag...@hotmail.com> wrote in message

news:ejZ3Pe1F...@TK2MSFTNGP02.phx.gbl...

IfThenElse

unread,
Oct 26, 2007, 11:00:46 AM10/26/07
to
Thanks everyone, I went the webservice method route.
the Problem I had was that one of the parameters name was not matching and
the Exception was generic that an internal error occurs.
So the example I was working with was correct.
Once I figured out where the SSRS logs are it pointed me to the right error
message.
The SSRS log files are important. I was fooled by looking into the SP
Parameters and not the Report Parameters I assumed they should match.
The developer made them different and out of sequence.

Thanks again,


"Bruce L-C [MVP]" <bruce_l...@hotmail.com> wrote in message
news:%23omsTX9...@TK2MSFTNGP05.phx.gbl...

IfThenElse

unread,
Oct 26, 2007, 11:01:50 AM10/26/07
to
Thank you for sharing this code.
That will help once I write against 2005
Some of the code I still don't understand, I hope to find explanations by
line item

Thanks again


"EMartinez" <emarti...@gmail.com> wrote in message
news:1193361420.2...@k79g2000hse.googlegroups.com...

azmiattia

unread,
Apr 28, 2010, 6:59:14 PM4/28/10
to
How can I read the URL line in the SSRS code. Please help

IfThenElse wrote:

Thank you for sharing this code.

26-Oct-07

Thank you for sharing this code.
That will help once I write against 2005

Some of the code I still do not understand, I hope to find explanations by
line item

Thanks again

Previous Posts In This Thread:

On Thursday, October 25, 2007 6:34 PM
IfThenElse wrote:

How to Programatically get a Report in PDF format from SSRS
Hi,

I have a report with parameters and need to get it via C# in PDF Format.

Need an example that works.

Thank you,

On Thursday, October 25, 2007 6:37 PM
IfThenElse wrote:

Re: How to Programatically get a Report in PDF format from SSRS


In Addition I am using SQL 2000 NOT 2005

On Thursday, October 25, 2007 7:29 PM
Norman Yuan wrote:

Call Reporting Services' web services.
Call Reporting Services' web services. There is a method called Render(),
that returns report in certain formt (PDF,HTML...) as binary stream. Simply
save the sttream to disk or send it back to user's browser (if the calls is
made via web application).

"IfThenElse" <sql_ag...@hotmail.com> wrote in message
news:ejZ3Pe1F...@TK2MSFTNGP02.phx.gbl...

On Thursday, October 25, 2007 9:17 PM
EMartinez wrote:

Re: How to Programatically get a Report in PDF format from SSRS

SSRSExecutionSvc.Warning[] warnings = null;

rs.ExecutionHeaderValue = execHeader;

execInfo = rs.LoadReport(strReportPath, strHistoryID);

Regards,

On Friday, October 26, 2007 9:40 AM
Bruce L-C [MVP] wrote:

Several sent posts to you about webservices.
Several sent posts to you about webservices. The other option is to embed an
IE control and then use URL integration (you just create the appropriate URL
string and set the property on the IE control). Search Books Online on the
web (RS 2000 books on line does not have as good a set of documentation on
URL integration as 2005 - url integration is the same for both versions so
the RS 2005 documentation will work for you).

With URL integration you have full control over the rendering format.


--
Bruce Loehle-Conger
MVP SQL Server Reporting Services


"IfThenElse" <sql_ag...@hotmail.com> wrote in message
news:ejZ3Pe1F...@TK2MSFTNGP02.phx.gbl...

On Friday, October 26, 2007 11:00 AM
IfThenElse wrote:

Thanks everyone, I went the webservice method route.
Thanks everyone, I went the webservice method route.
the Problem I had was that one of the parameters name was not matching and
the Exception was generic that an internal error occurs.
So the example I was working with was correct.
Once I figured out where the SSRS logs are it pointed me to the right error
message.
The SSRS log files are important. I was fooled by looking into the SP
Parameters and not the Report Parameters I assumed they should match.
The developer made them different and out of sequence.

Thanks again,


"Bruce L-C [MVP]" <bruce_l...@hotmail.com> wrote in message
news:%23omsTX9...@TK2MSFTNGP05.phx.gbl...

On Friday, October 26, 2007 11:01 AM
IfThenElse wrote:

Thank you for sharing this code.
Thank you for sharing this code.
That will help once I write against 2005

Some of the code I still do not understand, I hope to find explanations by
line item

Thanks again


Submitted via EggHeadCafe - Software Developer Portal of Choice
BOOK REVIEW: Effective C#, Second Edition [Addison Wesley]
http://www.eggheadcafe.com/tutorials/aspnet/b2f8766d-a4c1-4d5a-97af-c38852b3b455/book-review-effective-c.aspx

345...@gmail.com

unread,
Oct 27, 2016, 11:34:21 AM10/27/16
to
hi
i have the url and i want that URL to run without opening the browser,
following your code i have to define the parameters, its a problem cos i got them
in the url and i cant invoke them.
is there a way just run the url (with the parameters included) on the ssrs?
im desperate!!!!
thanks
0 new messages