当前位置:编程学习 > asp >>

步步为营 SharePoint 开发学习笔记系列 十、SharePoint web service 开发(下)

 

概要

 

接下来我们介绍Lists.UpdateListItems 在更新item做法和UserGroup.GetUserCollectionFromSite()的用法,请先学习步步为营SharePoint 开发学习笔记系列 八、SharePoint web service 开发(上),你将更容易学习web service的开发

 

Lists.UpdateListItems的用法

 

更新普通list的item的xml格式

 

view sourceprint?01 <Batch OnError="Continue" ListVersion="1" 

 

02 ViewName="270C0508-A54F-4387-8AD0-49686D685EB2"> 

 

03    <Method ID="1" Cmd="Update"> 

 

04       <Field Name="ID">4<Field> 

 

05       <Field Name="Field_Name">Value</Field> 

 

06    </Method> 

 

07    <Method ID="2" Cmd="Update"> 

 

08       <Field Name="ID" >6</Field> 

 

09       <Field Name="Field_Name">Value</Field> 

 

10    </Method> 

 

11 </Batch>

 

更新folder的item的xml格式

 

view sourceprint?01 <Batch OnError="Continue" PreCalc="TRUE" 

 

02 ListVersion="0" 

 

03 ViewName="{EF2F5A21-0FD0-4654-84ED-112B4F5A48F8}"> 

 

04    <Method ID="1" Cmd="Update"> 

 

05       <Field Name="ID">3</Field> 

 

06       <Field Name="owshiddenversion">1</Field> 

 

07       <Field Name="FileRef"> 

 

08          http://Server/[sites/][Site/]Shared  

 

09          Documents/Folder</Field> 

 

10       <Field Name="FSObjType">1</Field> 

 

11       <Field Name="BaseName">Name</Field> 

 

12    </Method> 

 

13 </Batch>

 

更新documents的item的xml格式

 

view sourceprint?01 <Batch OnError="Continue" PreCalc="TRUE" 

 

02 ListVersion="0" 

 

03 ViewName="{EF2F5A21-0FD0-4654-84ED-112B4F5A48F8}"> 

 

04    <Method ID="1" Cmd="Update"> 

 

05       <Field Name="ID">2</Field> 

 

06       <Field Name="owshiddenversion">1</Field> 

 

07       <Field Name="FileRef"> 

 

08          http://Server/[sites/][Site/]Shared  

 

09          Documents/File</Field> 

 

10       <Field Name="BaseName">Name</Field> 

 

11    </Method> 

 

12 </Batch>

 

我们更新item时xml格式的处理

 

view sourceprint?01 /// <summary> 

 

02 /// Get the approved XML Node that will be used for the insert method of the webservice 

 

03 /// </summary> 

 

04 /// <param name="batch"></param> 

 

05 /// <returns></returns> 

 

06 private XmlNode GetUpdateXmlNode(List<ListItemBE> batch) 

 

07 { 

 

08     StringBuilder xml = new StringBuilder(); 

 

09  

 

10     xml.Append(@"<Batch OnError=""Continue"">"); 

 

11     foreach (ListItemBE listItem in batch) 

 

12     { 

 

13         xml.AppendFormat(@"<Method ID=""{0}"" Cmd=""Update"">", listItem.Id); 

 

14         xml.Append(GetFieldInnerXml(listItem)); 

 

15         xml.Append("</Method>"); 

 

16     } 

 

17     xml.Append("</Batch>"); 

 

18  

 

19     //Get the Batch node 

 

20     XmlDocument doc = new XmlDocument(); 

 

21     doc.LoadXml(xml.ToString()); 

 

22  

 

23     XmlNode batchNode = doc.SelectSingleNode("//Batch"); 

 

24     return batchNode; 

 

25 }

 

更新item时调用sharepoint的web service的处理

 

view sourceprint?01 /// <summary> 

 

02 /// Insert the items 

 

03 /// </summary> 

 

04 /// <param name="batch"></param> 

 

05 /// <returns></returns> 

 

06 private UpdateResultBE UpdateItems(List<ListItemBE> batch) 

 

07 { 

 

08     //Get the Insert XML Node 

 

09     XmlNode batchNode = GetUpdateXmlNode(batch); 

 

10     XmlNode result = null; 

 

11  

 

12     _logger.Log("Started batch updating list Items"); 

 

13     try

 

14     { 

 

15         //Call the webservice 

 

16         result = _ws.UpdateListItems(_listProperty.ListName, batchNode); 

 

17     } 

 

18     catch (Exception ex) 

 

19     { 

 

20         _logger.Log(String.Fo

补充:Web开发 , ASP.Net ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,