时间:2019-12-15 16:23作者:admin来源:未知人气:316我要评论(0)
在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) { } |
6、 获取ListItem信息结果
7、 修改ListItem项
WebServices1.Lists listService = new WebServices1.Lists(); listService.Credentials = System.Net.CredentialCache.DefaultCredentials; string strBatch = "<Method ID='1' Cmd='Update'>" +//cmd参数,Update为更新,还有New、Delete "<Field Name='ID'>1</Field>" +//Name属性为字段名称,里面为字段值 "<Field Name='Title'>这个已经被修改了</Field></Method>"; XmlDocument xmlDoc = new System.Xml.XmlDocument(); System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch"); elBatch.InnerXml = strBatch; XmlNode ndReturn = listService.UpdateListItems("Test", elBatch);//第一个参数是列表名 Console.Write("操作成功"); |
8、修改ListItem后的结果
8、 以上是几个操作List的WebService的示例,自己也是参考微软的示例代码,读取出来的信息是Xml,然后在Xml中获取我们需要的信息就可以了。
Lists的SDK地址: http://msdn.microsoft.com/zh-cn/library/websvclists.lists_methods(v=office.12).aspx
相关阅读 SharePoint中Office文件无法打开的解决方案如何快速生成SharePoint测试大文件如何查询SharePoint Library中空文件夹?如何快速备份SharePoint Farm Solution如何解决Event Viewer中SharePoint Error - Event ID 8321SharePoint 2016 CU安装失败,"Exception: The upgraded database schema doesn't match the TargetSchema"的解决方案InfoPath Error “此文档库已经被重命名或删除,或者网络问题导致文件无法保存…” 的解决方案SharePoint 2013 App概述How to Shrink SharePoint Content Database Log File?Project Web App Feature无法开启的解决方案
热门文章 SharePoint 2016 图文安装教程 后面有激活序列号、密钥分享[SharePoint入门教程]一SharePoint发展、工具及术语如何用 SharePoint Online创建团队网站?SharePoint Iframe 报错“此内容不能显示在一个框架中”
最新文章
SharePoint中Office文件无法打开的解决方案如何快速生成SharePoint测试大文件
如何查询SharePoint Library中空文件夹?如何快速备份SharePoint Farm Solution如何解决Event Viewer中SharePoint Error - Event ID 8321SharePoint 2016 CU安装失败,"Exception: The upgraded database s
人气排行 SharePoint 2016 图文安装教程 后面有激活序列号、密钥分享[SharePoint入门教程]一SharePoint发展、工具及术语如何用 SharePoint Online创建团队网站?SharePoint Iframe 报错“此内容不能显示在一个框架中”SharePoint 2013 安装图解 SharePoint安装步骤图解教程SharePoint 如何开启访问请求[SharePoint入门教程]一SharePoint概述[SharePoint入门教程]一创建SharePoint母版页
盖楼回复X
(您的评论需要经过审核才能显示)
查看所有0条评论>>