在SharePoint的使用中,經常需要進行系統整合這樣的操作,我們作為SharePoint開發,就需要給其他系統提供介面,而SharePoint提供的WebService就很好的提供了這樣的功能,我們簡單瞭解下,通過SharePoint提供WebService對列表進行操作
步驟:
1、 首先,建立一個控制台程式,添加WebService的引用
地址http://<site>/_vti_bin/Lists.asmx
<site>為網站的地址,包括連接埠號碼
2、引用 - 右鍵 - 加入服務參考(如圖1)– 進階 – 添加Web引用 – URL處填寫WebService地址(如圖2)
(圖1)
(圖2)
3、 擷取List資訊
try
{
WebServices1.Lists listService = new GetListTest.WebServices1.Lists();
listService.Credentials = System.Net.CredentialCache.DefaultCredentials;
XmlNode ndLists = listService.GetList("Test");//參數列表名,String類型
Console.Write(ndLists.OuterXml);
}
catch (Exception ex)
{
Console.Write(ex.Message);
}
4、 擷取List資訊結果
5、 擷取ListItem資訊
//擷取ListItem資訊
WebServices1.Lists listService = new GetListTest.WebServices1.Lists();
listService.Credentials = System.Net.CredentialCache.DefaultCredentials;
XmlDocument xmlDoc = new System.Xml.XmlDocument();
XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");
XmlNode ndViewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "");
XmlNode ndQueryOptions = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "");
ndQueryOptions.InnerXml = ""; //Query設定
ndViewFields.InnerXml = ""; //視圖設定
ndQuery.InnerXml = ""; //Caml語句
try
{
XmlNode ndListItems = listService.GetListItems("Test", null, ndQuery, ndViewFields, "1", ndQueryOptions, null); //擷取列表內容
Console.Write(ndListItems.OuterXml); //輸出擷取的Xml內容
}
catch (System.Web.Services.Protocols.SoapException ex)
{
}
查看本欄目更多精彩內容:http://www.bianceng.cnhttp://www.bianceng.cn/web/sharepoint/
6、 擷取ListItem資訊結果