Discussion:
How to Programatically get a Report in PDF format from SSRS
(too old to reply)
IfThenElse
2007-10-25 22:34:05 UTC
Permalink
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
2007-10-25 22:37:04 UTC
Permalink
In Addition I am using SQL 2000 NOT 2005
Post by IfThenElse
Hi,
I have a report with parameters and need to get it via C# in PDF Format.
Need an example that works.
Thank you,
Norman Yuan
2007-10-25 23:29:51 UTC
Permalink
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).
Post by IfThenElse
In Addition I am using SQL 2000 NOT 2005
Post by IfThenElse
Hi,
I have a report with parameters and need to get it via C# in PDF Format.
Need an example that works.
Thank you,
Bruce L-C [MVP]
2007-10-26 13:40:50 UTC
Permalink
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
Post by IfThenElse
In Addition I am using SQL 2000 NOT 2005
Post by IfThenElse
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
2007-10-26 15:00:46 UTC
Permalink
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,
Post by Bruce L-C [MVP]
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
Post by IfThenElse
In Addition I am using SQL 2000 NOT 2005
Post by IfThenElse
Hi,
I have a report with parameters and need to get it via C# in PDF Format.
Need an example that works.
Thank you,
EMartinez
2007-10-26 01:17:00 UTC
Permalink
Post by IfThenElse
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
IfThenElse
2007-10-26 15:01:50 UTC
Permalink
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
Post by EMartinez
Post by IfThenElse
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";
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
unknown
2010-04-28 22:59:14 UTC
Permalink
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 200
Some of the code I still do not understand, I hope to find explanations b
line ite

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" <***@hotmail.com> wrote in message news:***@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
On Oct 25, 5:34 pm, "IfThenElse" <***@hotmail.com> wrote

Here's an example. It's a snippet from a web method I wrote to cal
and export an SSRS report programmatically. In this example,
declared a web reference named 'SSRSExecutionSvc' that points to th
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 = ne
SSRSExecutionSvc.ReportExecutionService()
//If you explicitly define a user below instead of th
default used here, you will need to make sure that the user accoun
has, at a minimum, Browser rights in the Report Manager
rs.Credentials
System.Net.CredentialCache.DefaultCredentials
rs.Url = "http://ServerName/reportserver
ReportExecution2005.asmx"

// Render argument
strReportPath = "/Reports Directory/ReportName"
strFormat = "PDF"
strDeviceInfo = @"<DeviceInfo><Toolbar>False</Toolbar><
DeviceInfo>"

// Prepare report parameter
SSRSExecutionSvc.ParameterValue[] parameters = ne
SSRSExecutionSvc.ParameterValue[1]

parameters[0] = new SSRSExecutionSvc.ParameterValue()
parameters[0].Name = "ORDERID"
parameters[0].Value = OrderID.ToString()

SSRSExecutionSvc.Warning[] warnings = null

SSRSExecutionSvc.ExecutionInfo execInfo = ne
SSRSExecutionSvc.ExecutionInfo()
SSRSExecutionSvc.ExecutionHeader execHeader = ne
SSRSExecutionSvc.ExecutionHeader()

rs.ExecutionHeaderValue = execHeader

execInfo = rs.LoadReport(strReportPath, strHistoryID)

rs.SetExecutionParameters(parameters, "en-us")
strSessionId = rs.ExecutionHeaderValue.ExecutionID

tr

result = rs.Render(strFormat, strDeviceInfo, ou
strExt, out strEncoding, out strMimeType, out warnings, ou
strStreamIDs)

execInfo = rs.GetExecutionInfo()

catch (SoapException SoapEx

return SoapEx.Detail.OuterXml.ToString()


// Write the Contents of the Invoice to a PDF Document
tr

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

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" <***@hotmail.com> wrote in message news:***@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]" <***@hotmail.com> wrote in message news:%***@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
3***@gmail.com
2016-10-27 15:33:56 UTC
Permalink
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

Loading...