用C#訪問SSRS自動匯出SSRS報表

來源:互聯網
上載者:User

標籤:

一、              建立一個winform應用程式WindowsFormsApplication1

二、              添加web引用 。

報表格服務:http://dbpdhkcax05:80/webservice/ReportService2005.asmx

報表執行服務:http://dbpdhkcax05:80/webservice/ReportExecution2005.asmx

右擊“引用”-> 加入服務參考->輸入URL地址點“前往”載入服務後點“進階”-服務引用設定->點“添加web引用”->在此畫面將2個服務都加入項目。

三、              web服務引用示。(web服務引用的節點一開始沒有,在添加web服務引用後自動產生).

四、              建一form用於輸入參數。

五、              點OK產生報表(VS2008)

1.插入命名空間引用

1 using WindowsFormsApplication1.dbpdhkcax05_rs;2 using WindowsFormsApplication1.dbpdhkcax05_rsexec;
View Code

2.Click OK 代碼

 1             dbpdhkcax05_rs.ReportingService2005 rs2005 = new ReportingService2005(); 2             dbpdhkcax05_rsexec.ReportExecutionService rsExec = new ReportExecutionService(); 3  4             rs2005.Credentials = System.Net.CredentialCache.DefaultCredentials; 5             rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials; 6             rsExec.Timeout = -1; 7  8             rs2005.Url = "http://dbpdhkcax05:80/webservice/ReportService2005.asmx?WSDL"; 9             rsExec.Url = "http://dbpdhkcax05:80/webservice/ReportExecution2005.asmx?WSDL";10 11 12             string reportPath = "/Operation/PortalReports/Reliability Details";13             string fileName = @"C:\\testRel.xls";14 15             string format = "EXCEL";16             string historyID = null;17             string devInfo = null;18             bool _forRendering = false;19 20             dbpdhkcax05_rs.ParameterValue[] _values = null;21             dbpdhkcax05_rs.ReportParameter[] _parm = null;22             dbpdhkcax05_rs.DataSourceCredentials[] _cred = null;23 24             _parm = rs2005.GetReportParameters(reportPath, historyID,_forRendering, _values, _cred);25 26             dbpdhkcax05_rsexec.ExecutionInfo execinfo = rsExec.LoadReport(reportPath, historyID);27 28             dbpdhkcax05_rsexec.ParameterValue[] parameters = new WindowsFormsApplication1.dbpdhkcax05_rsexec.ParameterValue[3];29             // Prepare report parameter.30             //ParameterValue[] parameters = new ParameterValue[3];31             parameters[0] = new dbpdhkcax05_rsexec.ParameterValue();32             parameters[0].Name = "StartDate";33             parameters[0].Value = txtFromDate.Text;34             parameters[1] = new dbpdhkcax05_rsexec.ParameterValue();35             parameters[1].Name = "EndDate";36             parameters[1].Value = txtToDate.Text; 37             parameters[2] = new dbpdhkcax05_rsexec.ParameterValue();38             parameters[2].Name = "Company";39             parameters[2].Value = txtCompanyId.Text;40 41             rsExec.SetExecutionParameters(parameters, "en-us");42             Byte[] results;43             string encoding = String.Empty;44             string mimeType = String.Empty;45             string extension = String.Empty;46             string[] streamIDs = null;47             dbpdhkcax05_rsexec.Warning[] warning = null;48             results = rsExec.Render(format, devInfo, out extension, out mimeType, out encoding, out warning, out streamIDs);49             using (FileStream stream = File.OpenWrite(fileName))50             {51                 stream.Write(results, 0, results.Length);52 53             }
View Code

 

用C#訪問SSRS自動匯出SSRS報表

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.