Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用C以PDF格式动态存储和发送SSRS报告#_C#_Sql Server_Reporting Services_Ssrs 2012_Rdl - Fatal编程技术网

C# 使用C以PDF格式动态存储和发送SSRS报告#

C# 使用C以PDF格式动态存储和发送SSRS报告#,c#,sql-server,reporting-services,ssrs-2012,rdl,C#,Sql Server,Reporting Services,Ssrs 2012,Rdl,我在SSRS中有一份报告,它将SalesRepCode和Email作为参数,以生成PDF收据。如果我使用报表查看器,它的工作状态应该是正常的 有了C#,我想为存在的每个SalesRep自动生成一个PDF,一旦呈现了PDF,我想将其存储在一个文件夹中,然后作为电子邮件附件发送 我已经看过了ReportingService2005类的MSDN文档,但这是指2005版本,我使用的是SSRS 2012,我仍然没有找到与我使用的版本相关的东西 有没有合适的方法来实现这一点 我已经将ReportingSer

我在SSRS中有一份报告,它将
SalesRepCode
Email
作为参数,以生成PDF收据。如果我使用报表查看器,它的工作状态应该是正常的

有了C#,我想为存在的每个SalesRep自动生成一个PDF,一旦呈现了PDF,我想将其存储在一个文件夹中,然后作为电子邮件附件发送

我已经看过了ReportingService2005类的MSDN文档,但这是指2005版本,我使用的是SSRS 2012,我仍然没有找到与我使用的版本相关的东西


有没有合适的方法来实现这一点

我已经将ReportingService2005Web服务与SQL 2012一起使用,它运行良好

简而言之,您可以添加对Web服务的引用,绑定参数,使用PDF调用Render(),并将ByTestStream保存为本地文件

有两个Web服务(报表服务和报表执行服务)令人困惑

我认为您只需使用Report Execution服务就可以成功

首先要检查的是,您可以在SSRS页面上看到.asmx文件 ()

您可以毫无问题地使用方法。您需要添加一个服务引用,该引用是报表服务器的引用

示例

下面的示例取自msdn,并进行了一些小改动。要查看原始示例,请查看。使用时,请注意将
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);
ReportExecutionService rs=新的ReportExecutionService();
rs.Credentials=System.Net.CredentialCache.DefaultCredentials;
rs.Url=”http://MyServer/reportserver/ReportExecution2005.asmx";
/*渲染参数*/
字节[]结果=空;
string reportPath=“/MyFolder/MyReport”;
string format=“PDF”;
字符串historyID=null;
字符串devInfo=@“False”;
/*准备报表参数*/
ParameterValue[]参数=新参数值[1];
参数[0]=新参数值();
参数[0]。Name=“SomeParameter”;
参数[0]。Value=“SomeValue”;
DataSourceCredentials[]凭证=null;
字符串showHideToggle=null;
字符串编码;
字符串模拟类型;
字符串扩展;
警告[]警告=null;
ParameterValue[]reportHistoryParameters=null;
字符串[]streamIDs=null;
ExecutionInfo ExecutionInfo=新的ExecutionInfo();
ExecutionHeader ExecutionHeader=新的ExecutionHeader();
rs.ExecutionHeaderValue=ExecutionHeader;
/*加载和呈现报告*/
execInfo=rs.LoadReport(reportPath,historyID);
rs.SetExecutionParameters(参数“en-us”);
字符串SessionId=rs.ExecutionHeaderValue.ExecutionID;
结果=rs.Render(格式、devInfo、输出扩展、输出编码、,
输出mimeType、输出警告、输出StreamID);
execInfo=rs.GetExecutionInfo();
/*保存文件*/
System.IO.File.writealBytes(@“d:\report.pdf”,result);

既然您使用的是C#,难道您不能将数据拉入网格,然后使用第三方nuget软件包将其导出为PDF格式吗?也许有点像PDFSharp。我看到的唯一问题是,您必须从头开始格式化所有内容,使其在PDFSharp上看起来“漂亮”,但它可以工作。嗨,我在Asp.NETCore中尝试过这个,但是它显示了一些不同的方法!