我在 SSRS 中有一份报告,它以 a 作为参数SalesRepCode
and Email
生成 PDF 收据。如果我使用报告查看器,它就会正常工作。
使用 C#,我想为每个存在的销售代表自动生成 PDF,一旦呈现 PDF,我想将其存储在文件夹中,然后将其作为电子邮件附件发送。
我查看了MSDN文档ReportingService2005
类,但这指的是2005年版本,我正在使用SSRS 2012,但我仍然没有找到与我正在使用的版本相关的东西。
有没有正确的方法来实现这一点?
您可以使用Render https://msdn.microsoft.com/en-us/library/reportexecution2005.reportexecutionservice.render.aspx的方法报告执行服务 https://msdn.microsoft.com/en-us/library/reportexecution2005.reportexecutionservice.aspx没有任何问题。您需要添加服务引用报告执行2005 https://msdn.microsoft.com/en-us/library/reportexecution2005.aspx哪一个是执行端点 https://msdn.microsoft.com/en-us/library/ms155398.aspx#Anchor_1报表服务器的。
Example
下面的示例取自 msdn,并进行了一些小的更改。要查看原始示例,请查看msdn 示例 https://msdn.microsoft.com/en-us/library/reportexecution2005.reportexecutionservice.render.aspx#Anchor_2。使用时注意使用PDF
作为格式以及关于报告路径,它应该是报告的路径,开头为/
并以报告名称结尾,不带.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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)