1、報表輸出資訊:
下列是我們希望匯出的報表資訊。
2、當開啟專案後,先加入第一個Web Service。
路徑請輸入:http://myreportserver/reportserver/reportservice2005.asmx
參考名稱請使用預設值
3、依序再加入第二個Web Service
路徑請輸入:http://myreportserver/reportserver/reportexecution2005.asmx
參考名稱:ReportExecutionService
4、接著再將下列的程式碼輸入即可,如果你要進行測試時,請修改下列的程式行。
- 17行 -> rs.Credentials = new System.Net.NetworkCredential("caryhsu", " p@ssword ", " microsoft ");
- 請依序輸入使用者名稱、密碼、DomainName
- 20行 -> string reportPath = "/ssrs_render_test";
- 報表名稱
- 26行 -> string fileName = @"c:\share\ssrs_render_test.xls";
- 輸出的位置
- 33行 -> rsExec.Credentials = new System.Net.NetworkCredential("caryhsu", "p@ssword", "microsoft");
- 請依序輸入使用者名稱、密碼、DomainName
- 41+42行 -> 報表參數
- parameters[0].Name = "PurchaseOrderID"; >> 報表參數 -> 欄位名稱
- parameters[0].Value = "2"; >> 報表參數 -> 欄位值
程式碼範例:
// Create object and set credential to RSservice
ReportExecutionService.ReportExecutionService rsExec = new ReportExecutionService.ReportExecutionService();
WebReference.ReportingService2005 rs = new WebReference.ReportingService2005();
rs.Credentials = new System.Net.NetworkCredential("caryhsu", "p@ssword", "microsoft");
// Render arguments
string reportPath = "/ssrs_render_test"; //path is from root(ReportServer)
string format = "EXCEL"; //Export Format
string deviceInfo = null;
string extension;
string[] streamIDs;
ReportExecutionService.Warning[] warnings;
string fileName = @"c:\share\ssrs_render_test.xls";
string encoding;
string mimeType;
try
{
// Load the report.
rsExec.Credentials = new System.Net.NetworkCredential("caryhsu", "p@ssword", "microsoft");
ReportExecutionService.ExecutionInfo info = rsExec.LoadReport(reportPath, null);
WebReference.ReportParameter[] rsparameters = rs.GetReportParameters(reportPath, null, false, null, null);
if (rsparameters.Length > 0)
{
ReportExecutionService.ParameterValue[] parameters = new ReportExecutionService.ParameterValue[1];
parameters[0] = new ReportExecutionService.ParameterValue();
parameters[0].Name = "PurchaseOrderID";
parameters[0].Value = "2";
rsExec.SetExecutionParameters(parameters, "en-us");
}
byte[] reportBytes = rsExec.Render(
format,
deviceInfo,
out extension,
out mimeType,
out encoding,
out warnings,
out streamIDs);
// Write report bytes to a file.
using (FileStream stream = File.OpenWrite(fileName))
stream.Write(reportBytes, 0, reportBytes.Length);
}
catch (SoapException e)
{
Console.WriteLine(e.Detail.OuterXml);
}
參考連結:
Available Rendering Extensions (Reporting Services)
http://technet.microsoft.com/en-us/library/cc627537(v=sql.100).aspx
Render Method
http://technet.microsoft.com/en-us/library/aa258532(v=sql.80).aspx
關鍵字:Reporting Service、Render、ReportExecutionService
沒有留言:
張貼留言