2013-12-17 35 views
0

我一直在尝试使用报告Web服务将SSRS报告转换为PDF并保存到本地驱动器。虽然我能够生成相应的pdf文件,但文件的内容不见了。我检查了我想要转换的报告不是空的。只有标题部分存在于生成的pdf文件中。以下是我正在使用的代码:使用Reporting Services将SSRS报告另存为pdf

protected void GeneratePDFFromReport(object sender, EventArgs e) 
    { 
     RS2005.ReportingService2005 rs; 
     RE2005.ReportExecutionService rsExec; 

     // Create a new proxy to the web service 
     rs = new RS2005.ReportingService2005(); 
     rsExec = new RE2005.ReportExecutionService(); 

     // Authenticate to the Web service using Windows credentials 
     rs.Credentials = new System.Net.NetworkCredential("username", "password", "domain"); 
     rsExec.Credentials = new System.Net.NetworkCredential("username", "password", "domain"); 
     //rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials; 

     rs.Url = "http://servername/reportserver/reportservice2005.asmx"; 
     rsExec.Url = "http://servername/reportserver/reportexecution2005.asmx"; 

     string historyID = null; 
     string deviceInfo = null; 
     string format = "PDF"; 
     Byte[] results; 
     string encoding = String.Empty; 
     string mimeType = "application/pdf"; 
     string extension = String.Empty; 
     RE2005.Warning[] warnings = null; 
     string[] streamIDs = null; 

     // Path of the Report - XLS, PDF etc. 
     string fileName = @"C:\Report\MemberReport.pdf"; 
     // Name of the report - Please note this is not the RDL file. 
     string _reportName = @"/ReportFolder/ReportName"; 
     string _historyID = null; 
     bool _forRendering = false; 
     RS2005.ParameterValue[] _values = null; 
     RS2005.DataSourceCredentials[] _credentials = null; 
     RS2005.ReportParameter[] _parameters = null; 

     try 
     { 
      _parameters = rs.GetReportParameters(_reportName, _historyID, _forRendering, _values, _credentials); 
      RE2005.ExecutionInfo ei = rsExec.LoadReport(_reportName, historyID); 

      results = rsExec.Render(format, deviceInfo, 
         out extension, out encoding, 
         out mimeType, out warnings, out streamIDs); 

      try 
      { 
       FileStream stream = File.Create(fileName, results.Length); 
       stream.Write(results, 0, results.Length); 
       stream.Close(); 
      } 
      catch { } 

      results = null; 
     } 
     catch (Exception ex) 
     { 
      throw ex; 
     } 
    } 

任何帮助将不胜感激。谢谢。

回答

0

假设SSRS正在使用的浏览器工作正常,请修改你发布的代码如下所示:

1)设备信息的字符串,请进行如下设置:

string deviceInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"; //Initial value was null 

2)创建头实例在使用网络呼叫LoadReport之前:

ExecutionHeader execHeader = new ExecutionHeader(); 
RE2005.ExecutionHeaderValue = execHeader; 
相关问题