设为首页 收藏本站
查看: 589|回复: 0

[经验分享] sharepoint Lists Web service 用法

[复制链接]
发表于 2015-9-25 07:49:49 | 显示全部楼层 |阅读模式
  概述
  在sharepoint 项目中,后期做数据迁移时,会用到sharepoint的web service来完成把数据导入sharepoint站点的功能。
  web service 名称:
  http://[site]/_vti_bin/Lists.asmx
  
  我们用它来新增,修改或者删除当前站点特定list 的item操作。
  调用的方法:
[SoapDocumentMethodAttribute("http://schemas.microsoft.com/sharepoint/soap/UpdateListItems", RequestNamespace="http://schemas.microsoft.com/sharepoint/soap/", ResponseNamespace="http://schemas.microsoft.com/sharepoint/soap/", Use=SoapBindingUse.Literal, ParameterStyle=SoapParameterStyle.Wrapped)]
public XmlNode UpdateListItems (
string listName,
XmlNode updates
)
  
  
  listName:当前站点list的名字。
  操作list的item则通过XmlNode来完成。
  更改普通list里item对应field Name的xml代码:

<Batch OnError=&quot;Continue&quot; ListVersion=&quot;1&quot;
ViewName=&quot;270C0508-A54F-4387-8AD0-49686D685EB2&quot;>
<Method ID=&quot;1&quot; Cmd=&quot;Update&quot;>
<Field Name=&quot;ID&quot;>4<Field>
<Field Name=&quot;Field_Name&quot;>Value</Field>
</Method>
<Method ID=&quot;2&quot; Cmd=&quot;Update&quot;>
<Field Name=&quot;ID&quot; >6</Field>
<Field Name=&quot;Field_Name&quot;>Value</Field>
</Method>
</Batch>
  
  新增list里item的xml代码:

<Batch OnError=&quot;Continue&quot; ListVersion=&quot;1&quot;
ViewName=&quot;270C0508-A54F-4387-8AD0-49686D685EB2&quot;>
<Method ID=&quot;1&quot; Cmd=&quot;New&quot;>
<Field Name='ID'>New</Field>
<Field Name=&quot;Title&quot;>Value</Field>
<Field Name=&quot;Date_Column&quot;>2007-3-25</Field>
<Field Name=&quot;Date_Time_Column&quot;>
2006-1-11T09:15:30Z</Field>
</Method>
</Batch>
  
  
  删除list里item的xml代码:

<Batch OnError=&quot;Continue&quot; ListVersion=&quot;1&quot;
ViewName=&quot;270C0508-A54F-4387-8AD0-49686D685EB2&quot;>
<Method ID=&quot;1&quot; Cmd=&quot;Delete&quot;>
<Field Name='ID'>2</Field>
</Method>
<Method ID=&quot;2&quot; Cmd=&quot;Delete&quot;>
<Field Name='ID'>8</Field>
</Method>
</Batch>
  
  
  document libraries操作:
  新建文件夹xml的代码:

<Batch OnError=&quot;Continue&quot; PreCalc=&quot;TRUE&quot;
ListVersion=&quot;0&quot;
ViewName=&quot;{EF2F5A21-0FD0-4654-84ED-112B4F5A48F8}&quot;>
<Method ID=&quot;1&quot; Cmd=&quot;New&quot;>
<Field Name=&quot;ID&quot;>New</Field>
<Field Name=&quot;FSObjType&quot;>1</Field>
<Field Name=&quot;BaseName&quot;>Name</Field>
</Method>
</Batch>
  
  
  
  更新文件夹的xml代码:

<Batch OnError=&quot;Continue&quot; PreCalc=&quot;TRUE&quot;
ListVersion=&quot;0&quot;
ViewName=&quot;{EF2F5A21-0FD0-4654-84ED-112B4F5A48F8}&quot;>
<Method ID=&quot;1&quot; Cmd=&quot;Update&quot;>
<Field Name=&quot;ID&quot;>3</Field>
<Field Name=&quot;owshiddenversion&quot;>1</Field>
<Field Name=&quot;FileRef&quot;>
http://Server/[sites/][Site/]Shared
Documents/Folder</Field>
<Field Name=&quot;FSObjType&quot;>1</Field>
<Field Name=&quot;BaseName&quot;>Name</Field>
</Method>
</Batch>
  
  
  删除文件夹xml代码:

<Batch OnError=&quot;Continue&quot; PreCalc=&quot;TRUE&quot;
ListVersion=&quot;0&quot;
ViewName=&quot;{EF2F5A21-0FD0-4654-84ED-112B4F5A48F8}&quot;>
<Method ID=&quot;1&quot; Cmd=&quot;Delete&quot;>
<Field Name=&quot;ID&quot;>4</Field>
<Field Name=&quot;FileRef&quot;>
http://Server/[sites/][Site/]Shared
Documents/Folder</Field>
</Method>
</Batch>
  
  
  更新文件夹里文件的xml代码:

<Batch OnError=&quot;Continue&quot; PreCalc=&quot;TRUE&quot;
ListVersion=&quot;0&quot;
ViewName=&quot;{EF2F5A21-0FD0-4654-84ED-112B4F5A48F8}&quot;>
<Method ID=&quot;1&quot; Cmd=&quot;Update&quot;>
<Field Name=&quot;ID&quot;>2</Field>
<Field Name=&quot;owshiddenversion&quot;>1</Field>
<Field Name=&quot;FileRef&quot;>
http://Server/[sites/][Site/]Shared
Documents/File</Field>
<Field Name=&quot;BaseName&quot;>Name</Field>
</Method>
</Batch>
  
  
  删除文件夹里文件的xml代码:

<Batch OnError=&quot;Continue&quot; PreCalc=&quot;TRUE&quot;
ListVersion=&quot;0&quot;
ViewName=&quot;{EF2F5A21-0FD0-4654-84ED-112B4F5A48F8}&quot;>
<Method ID=&quot;1&quot; Cmd=&quot;Delete&quot;>
<Field Name=&quot;ID&quot;>3</Field>
<Field Name=&quot;FileRef&quot;>
http://Server/[sites/][Site/]Shared
Documents/File</Field>
</Method>
</Batch>
  
  
  调用方法:

Web_Reference_Folder.Lists listService = new Web_Reference_Folder.Lists();
listService.Credentials= System.Net.CredentialCache.DefaultCredentials;
string strBatch = &quot;<Method ID='1' Cmd='Update'>&quot; +
&quot;<Field Name='ID'>4</Field>&quot; +
&quot;<Field Name='Field_Number'>999</Field></Method>&quot; +
&quot;<Method ID='2' Cmd='Update'><Field Name='ID' >6</Field>&quot; +
&quot;<Field Name='Field_DateTime'>
2003-11-11T09:15:30Z</Field></Method>&quot;;
XmlDocument xmlDoc = new System.Xml.XmlDocument();
System.Xml.XmlElement elBatch = xmlDoc.CreateElement(&quot;Batch&quot;);
elBatch.SetAttribute(&quot;OnError&quot;,&quot;Continue&quot;);
elBatch.SetAttribute(&quot;ListVersion&quot;,&quot;1&quot;);
elBatch.SetAttribute(&quot;ViewName&quot;,
&quot;0d7fcacd-1d7c-45bc-bcfc-6d7f7d2eeb40&quot;);
elBatch.InnerXml = strBatch;
XmlNode ndReturn = listService.UpdateListItems(&quot;List_Name&quot;, elBatch);
MessageBox.Show(ndReturn.OuterXml);
  
  
  返回XmlNode代码的格式:

<Results xmlns=&quot;http://schemas.microsoft.com/sharepoint/soap/&quot;>
<Result ID=&quot;1,Update&quot;>
<ErrorCode>0x00000000</ErrorCode>
<z:row ows_ID=&quot;4&quot; ows_Title=&quot;Title&quot;
ows_Modified=&quot;2003-06-19 20:31:21&quot;
ows_Created=&quot;2003-06-18 10:15:58&quot;
ows_Author=&quot;3;#User1_Display_Name&quot;
ows_Editor=&quot;7;#User2_Display_Name&quot; ows_owshiddenversion=&quot;3&quot;
ows_Attachments=&quot;-1&quot;
ows__ModerationStatus=&quot;0&quot; ows_LinkTitleNoMenu=&quot;Title&quot;
ows_LinkTitle=&quot;Title&quot;
ows_SelectTitle=&quot;4&quot; ows_Order=&quot;400.000000000000&quot;
ows_GUID=&quot;{4962F024-BBA5-4A0B-9EC1-641B731ABFED}&quot;
ows_DateColumn=&quot;2003-09-04 00:00:00&quot;
ows_NumberColumn=&quot;791.00000000000000&quot;
xmlns:z=&quot;#RowsetSchema&quot; />
</Result>
<Result ID=&quot;2,Update&quot;>
<ErrorCode>0x00000000</ErrorCode>
<z:row ows_ID=&quot;6&quot; ows_Title=&quot;Title&quot;
ows_Modified=&quot;2003-06-19 20:31:22&quot;
ows_Created=&quot;2003-06-18 19:07:14&quot;
ows_Author=&quot;2;#User1_Display_Name&quot;
ows_Editor=&quot;6;#User2_Display_Name&quot; ows_owshiddenversion=&quot;4&quot;
ows_Attachments=&quot;0&quot; ows__ModerationStatus=&quot;0&quot;
ows_LinkTitleNoMenu=&quot;Title&quot;
ows_LinkTitle=&quot;Title&quot; ows_SelectTitle=&quot;6&quot;
ows_Order=&quot;600.000000000000&quot;
ows_GUID=&quot;{2E8D2505-98FD-4E3E-BFDA-0C3DEBE483F7}&quot;
ows_DateColumn=&quot;2003-06-23 00:00:00&quot;
ows_NumberColumn=&quot;9001.00000000000000&quot;
xmlns:z=&quot;#RowsetSchema&quot; />
</Result>
...
</Results>
  
  
  取返回值的方法:

            foreach (XmlNode node in nodes)
{
if (node.Name == &quot;rs:data&quot;)
{
for (int i = 0; i < node.ChildNodes.Count; i++)
{
if (node.ChildNodes.Name == &quot;z:row&quot;)
{
string ID = node.ChildNodes.Attributes[&quot;ows_ID&quot;].Value;
string Title = node.ChildNodes.Attributes[&quot;ows_Title&quot;].Value;
}
}
}
}
  
  
  总结
  简单介绍了Lists.UpdateListItems (string listName,XmlNode node)的用法。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-118356-1-1.html 上篇帖子: SharePoint 2007 迁移所有数据库 下篇帖子: 01-- sharepoint 2010开发概述
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表