4

I have a report in SSRS that takes as a parameter a SalesRepCode and Email to generate a PDF receipt. It's working as it should be if I'm using the Report Viewer.

With C#, I'd like to automatically generate a PDF for each SalesRep that exists, once the PDF is rendered, I'd like to store it on a folder and then send it as an email attachment.

I have looked at the MSDN documentation of the ReportingService2005 Class, but this refers to the 2005 version, and I'm using SSRS 2012 and I still havent found a thing related to the version I'm using.

Is there a proper way of making this happen?

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
gmwill934
  • 609
  • 1
  • 10
  • 27
  • Since you are using C#, can't you pull the data into a grid, then from there export out as a PDF using a third party nuget package? Perhaps something like PDFSharp. The only problem I see is that you'd have to format everything from scratch to make it look "pretty" on PDFSharp, but it could work. [link](http://www.pdfsharp.com/PDFsharp/index.php?option=com_content&task=view&id=15&Itemid=29) – dkolln Oct 11 '16 at 15:23

2 Answers2

3

You can use Render method of ReportExecutionService without any problem. You need to add a service reference to ReportExecution2005 which is the Execution Endpoint of report server.

Example

Below example has been taken from msdn and used by some small changes. To see the original example take a look at msdn example. When using, pay attention to use PDF as format and also about the report path it should be the path of your report starting by / and ending with report name without .rdl.

ReportExecutionService rs = new ReportExecutionService();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
rs.Url = "http://MyServer/reportserver/ReportExecution2005.asmx";
/* Render arguments */
byte[] result = null;
string reportPath = "/MyFolder/MyReport"; 
string format = "PDF";
string historyID = null;
string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";          
/* Prepare report parameter.*/
ParameterValue[] parameters = new ParameterValue[1];
parameters[0] = new ParameterValue();
parameters[0].Name = "SomeParameter";
parameters[0].Value = "SomeValue";
DataSourceCredentials[] credentials = null;
string showHideToggle = null;
string encoding;
string mimeType;
string extension;
Warning[] warnings = null;
ParameterValue[] reportHistoryParameters = null;
string[] streamIDs = null;
ExecutionInfo execInfo = new ExecutionInfo();
ExecutionHeader execHeader = new ExecutionHeader();
rs.ExecutionHeaderValue = execHeader; 
/*Load and Render Report*/
execInfo = rs.LoadReport(reportPath, historyID);
rs.SetExecutionParameters(parameters, "en-us");
String SessionId = rs.ExecutionHeaderValue.ExecutionID;
result = rs.Render(format, devInfo, out extension, out encoding, 
    out mimeType, out warnings, out streamIDs);
execInfo = rs.GetExecutionInfo();
/*Save File*/
System.IO.File.WriteAllBytes(@"d:\report.pdf", result);
Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
0

I've used the ReportingService2005 Web Service with SQL 2012 and it works fine.

In a nutshell - You add the reference to the Web Service, Bind Params, Call Render() with PDF and save the ByteStream as a local file.

There are confusingly 2 Web Services (Report Service & Report Execution Service)

I think you can get away with just using the Report Execution Service.

First thing to check is that you can see the .asmx file on your SSRS Page (http://...ReportExecution2005.asmx)

john McTighe
  • 1,181
  • 6
  • 8