Reporting Server有提供一些WebService讓使用者自行開發客製化的Web或是AP的界面
在這裡就試著介紹一些常用到的WS函數 (此處只介紹程式該如何寫, 更詳細的物件屬性請至MSDN上查詢)
(PS.參考來自官方文件:http://msdn.microsoft.com/zh-tw/library/cc282570.aspx)
環境:ReportingServer 2005 -請注意版本
1、如果本機已經有安裝ReportingServer的話即可直接使用宣告(官方此元件為:ReportingServicesLibrary.dll)
ReportingService2005 rs = new ReportingService2005();
(若無的話可透過Reporting server的Web-Service做參考)
2、由於Reporting Server所用的權限登入是透過微軟的Nt 帳號所以要透過以下指定來獲得驗證
rs.Credentials = System.Net.CredentialCache.DefaultCredentials; (直接用電腦帳號)
rs.Credentials = new System.Net.NetworkCredential("帳號","密碼","網域名稱"); (使用帳號登入)
3、函數
A、產生資料夾
Createfolder(欲新增的資料夾名稱, 伺服器上儲存的路徑, 其它屬性 );
欲新增的資料夾名稱=string();
伺服器上儲存的路徑= string();
其它屬性 = propoties[];
example:
string folderName = "Budget";
try
{
rs.CreateFolder(folderName, "/ReportingServerTesting", null);
Console.WriteLine("Folder created: {0}", folderName);
}
catch (Exception ex)
{
Response.Write(ex.Message);
//Console.WriteLine(e.Detail.InnerXml);
}
ps.或語propoties有其意義, 但在測試之後我看不出其意義, 故我放了一個null, 若有人了解的話可以回饋一下
B、上傳報表
CreateReport(檔案名稱, 路徑, 是否覆蓋, byte, 其它屬性);
檔案名稱=string();
路徑=string();
是否覆蓋= boolean;
byte=byte[];
其它屬性=propoties[];
example:
Byte[] definition = null;
string name = "MyReportA";
FileStream stream = File.OpenRead(路徑);
definition = new Byte[stream.Length];
stream.Read(definition, 0, (int)stream.Length);
stream.Close();
try
{
rs.CreateReport(name, "/test", true, definition, null);
Response.Write("Report:" + name + " created successfully with no warnings");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
C、設定報表的資料來源(DataSet)
SetReportDataSource(報表路徑, 資料集合)
example:
ReportingService2005 .DataSourceReference reference = new ReportingService2005.DataSourceReference();
reference.Reference = "/ReportingServerTesting/Datasourc1";
ReportingService2005.DataSource[] dsarray = new ReportingService2005.DataSource[1]; //代表可以加入多個datasource
ReportingService2005.DataSource ds3 = new ReportingService2005.DataSource();
ds3.Item = (ReportingService2005.DataSourceDefinitionOrReference)reference;
ds3.Name = "datasetName"; //(此處的dataSource名稱必需對應Report內的dataset Name)
dsarray[0] = ds3;
rs.SetItemDataSources("/Test1/MyReport", dsarray);
D、列出該資料夾下所有的節點
ListChildren(欲列出的路徑,是否回傳全部)
欲列出的路徑 =string();
是否回傳全部 = boolean();
回傳值為:CatalogItem [];
example:
ArrayList RportPath = new ArrayList ();
CatalogItem[] catalogits = rs.ListChildren("/" + FolderRoot, true);
foreach (au3dp3.CatalogItem aa in catalogits)
{
RportPath.Add(aa.Name);
}
留言列表