首页 > 代码库 > Sharepoint CAML 增删改查 List
Sharepoint CAML 增删改查 List
Lists.UpdateListItems 方法 (websvcLists)
命名空间: websvcLists
程序集: STSSOAP (在 stssoap.dll 中)
[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
A string that contains the name of the list. It is recommended that you use the list GUID surrounded by curly braces (i.e.,
"{
GUID}")
, but you can also use the list display name.
- updates
A Batch element that contains one or more methods for adding, modifying, or deleting items and that can be assigned to a System.Xml.XmlNode object.
The following example shows how to modify column values for two specified items.
XML复制<Batch OnError="Continue" ListVersion="1" ViewName="270C0508-A54F-4387-8AD0-49686D685EB2"> <Method ID="1" Cmd="Update"> <Field Name="ID">4<Field> <Field Name="Field_Name">Value</Field> </Method> <Method ID="2" Cmd="Update"> <Field Name="ID" >6</Field> <Field Name="Field_Name">Value</Field> </Method></Batch>
An empty ViewName attribute in the Batch element causes the default view to be used. The ID attribute in each Method element uniquely identifies the specific update so that errors and return values can be properly identified. Each method that is posted contains Field elements that specify the ID of the item and the new field value for the item. The field ID does not correspond to the index of the item in the collection of items for the list.
The following example shows the format for adding a new item that contains both a Date value and a DateTime value.
XML复制<Batch OnError="Continue" ListVersion="1" ViewName="270C0508-A54F-4387-8AD0-49686D685EB2"> <Method ID="1" Cmd="New"> <Field Name=‘ID‘>New</Field> <Field Name="Title">Value</Field> <Field Name="Date_Column">2007-3-25</Field> <Field Name="Date_Time_Column"> 2006-1-11T09:15:30Z</Field> </Method></Batch>
The following example shows how to delete two items.
XML复制<Batch OnError="Continue" ListVersion="1" ViewName="270C0508-A54F-4387-8AD0-49686D685EB2"> <Method ID="1" Cmd="Delete"> <Field Name=‘ID‘>2</Field> </Method> <Method ID="2" Cmd="Delete"> <Field Name=‘ID‘>8</Field> </Method></Batch>
注意: IDs for deleted items are maintained after delete operations. Consequently, the example deletes the second and eighth items in the list, but 2 and 8 are not reassigned as the IDs of other items.
For descriptions of the various formats used for field types that can be passed in this parameter see SPListItem.
The following examples show the methods that can be posted for operations related to document libraries:
Create a folder
XML复制<Batch OnError="Continue" PreCalc="TRUE" ListVersion="0" ViewName="{EF2F5A21-0FD0-4654-84ED-112B4F5A48F8}"> <Method ID="1" Cmd="New"> <Field Name="ID">New</Field> <Field Name="FSObjType">1</Field> <Field Name="BaseName">Name</Field> </Method></Batch>
Update a folder
XML复制<Batch OnError="Continue" PreCalc="TRUE" ListVersion="0" ViewName="{EF2F5A21-0FD0-4654-84ED-112B4F5A48F8}"> <Method ID="1" Cmd="Update"> <Field Name="ID">3</Field> <Field Name="owshiddenversion">1</Field> <Field Name="FileRef"> http://Server/[sites/][Site/]Shared Documents/Folder</Field> <Field Name="FSObjType">1</Field> <Field Name="BaseName">Name</Field> </Method></Batch>
Delete a folder
XML复制<Batch OnError="Continue" PreCalc="TRUE" ListVersion="0" ViewName="{EF2F5A21-0FD0-4654-84ED-112B4F5A48F8}"> <Method ID="1" Cmd="Delete"> <Field Name="ID">4</Field> <Field Name="FileRef"> http://Server/[sites/][Site/]Shared Documents/Folder</Field> </Method></Batch>
Update documents
XML复制<Batch OnError="Continue" PreCalc="TRUE" ListVersion="0" ViewName="{EF2F5A21-0FD0-4654-84ED-112B4F5A48F8}"> <Method ID="1" Cmd="Update"> <Field Name="ID">2</Field> <Field Name="owshiddenversion">1</Field> <Field Name="FileRef"> http://Server/[sites/][Site/]Shared Documents/File</Field> <Field Name="BaseName">Name</Field> </Method></Batch>
Delete documents
XML复制<Batch OnError="Continue" PreCalc="TRUE" ListVersion="0" ViewName="{EF2F5A21-0FD0-4654-84ED-112B4F5A48F8}"> <Method ID="1" Cmd="Delete"> <Field Name="ID">3</Field> <Field Name="FileRef"> http://Server/[sites/][Site/]Shared Documents/File</Field> </Method></Batch>
返回值
An XMLDATA fragment in the following form that shows the status of each method block posted through the updates parameter and that can be assigned to a System.Xml.XmlNode object. For items successfully updated, a row fragment is returned with the updated row values.<Results xmlns="http://schemas.microsoft.com/sharepoint/soap/"> <Result ID="1,Update"> <ErrorCode>0x00000000</ErrorCode> <z:row ows_ID="4" ows_Title="Title" ows_Modified="2003-06-19 20:31:21" ows_Created="2003-06-18 10:15:58" ows_Author="3;#User1_Display_Name" ows_Editor="7;#User2_Display_Name" ows_owshiddenversion="3" ows_Attachments="-1" ows__ModerationStatus="0" ows_LinkTitleNoMenu="Title" ows_LinkTitle="Title" ows_SelectTitle="4" ows_Order="400.000000000000" ows_GUID="{4962F024-BBA5-4A0B-9EC1-641B731ABFED}" ows_DateColumn="2003-09-04 00:00:00" ows_NumberColumn="791.00000000000000" xmlns:z="#RowsetSchema" /> </Result> <Result ID="2,Update"> <ErrorCode>0x00000000</ErrorCode> <z:row ows_ID="6" ows_Title="Title" ows_Modified="2003-06-19 20:31:22" ows_Created="2003-06-18 19:07:14" ows_Author="2;#User1_Display_Name" ows_Editor="6;#User2_Display_Name" ows_owshiddenversion="4" ows_Attachments="0" ows__ModerationStatus="0" ows_LinkTitleNoMenu="Title" ows_LinkTitle="Title" ows_SelectTitle="6" ows_Order="600.000000000000" ows_GUID="{2E8D2505-98FD-4E3E-BFDA-0C3DEBE483F7}" ows_DateColumn="2003-06-23 00:00:00" ows_NumberColumn="9001.00000000000000" xmlns:z="#RowsetSchema" /> </Result> ...</Results>
The following code example modifies the values of two different field values within two items in a list on the current site. The example uses an XmlDocument object to create XmlNode objects for parameters.
This example requires that a using (Visual C#) or Imports (Visual Basic) directive be included for the System.Xml namespace.
Web_Reference_Folder.Lists listService = new Web_Reference_Folder.Lists();listService.Credentials= System.Net.CredentialCache.DefaultCredentials;string strBatch = "<Method ID=‘1‘ Cmd=‘Update‘>" + "<Field Name=‘ID‘>4</Field>" + "<Field Name=‘Field_Number‘>999</Field></Method>" + "<Method ID=‘2‘ Cmd=‘Update‘><Field Name=‘ID‘ >6</Field>" + "<Field Name=‘Field_DateTime‘> 2003-11-11T09:15:30Z</Field></Method>"; XmlDocument xmlDoc = new System.Xml.XmlDocument();System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch");elBatch.SetAttribute("OnError","Continue");elBatch.SetAttribute("ListVersion","1");elBatch.SetAttribute("ViewName", "0d7fcacd-1d7c-45bc-bcfc-6d7f7d2eeb40");elBatch.InnerXml = strBatch;XmlNode ndReturn = listService.UpdateListItems("List_Name", elBatch);MessageBox.Show(ndReturn.OuterXml);
<script type="text/javascript">// =scripts.length){delete mtps.injectScripts;return}script=scripts[index];elem=document.createElement("script");elem.className="mtps-injected";elem.async=!1;var isLoaded=!1,timeoutId=0,injectNextFnName="",injectNext=elem.onerror=function(){isLoaded||(isLoaded=!0,inject(scripts,index+1),window.clearTimeout(timeoutId),elem.onload=elem.onerror=elem.onreadystatechange=null,injectNextFnName&&delete mtps[injectNextFnName],elem.removeEventListener&&elem.removeEventListener("load",injectNext,!1))};elem.addEventListener?elem.addEventListener("load",injectNext,!1):elem.readyState==="uninitialized"?elem.onreadystatechange=function(){(this.readyState==="loaded"||this.readyState==="complete")&&injectNext()}:elem.onload=injectNext;script.hasOwnProperty("url")?(timeoutId=window.setTimeout(injectNext,12e4),elem.src=http://www.mamicode.com/script.url):(injectNextFnName="_injectNextScript_"+index,mtps[injectNextFnName]=injectNext,timeoutId=window.setTimeout(injectNext,2e3),elem.text="try {\n"+script.txt+"\n} finally { MTPS."+injectNextFnName+" && MTPS."+injectNextFnName+"(); }");parent.appendChild(elem)}var mtps=window.MTPS||(window.MTPS={}),parent=document.getElementsByTagName("head")[0];mtps.injectScripts=function(scripts){inject(preload(scripts),0)}})(window,document);MTPS.injectScripts([ { txt: "/**/\r\n(window.MTPS || (window.MTPS = {})).cdnDomains || (window.MTPS.cdnDomains = { \r\n\t\"image\": \"http://i.msdn.microsoft.com\", \r\n\t\"js\": \"http://i2.msdn.microsoft.com\", \r\n\t\"css\": \"http://i3.msdn.microsoft.com\", \r\n\t\"xap\": \"http://msdn.microsoft.com\"\r\n});\r\n/**/" }, { url: "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js" }, { txt: "//\n var literalNormalizedUrl = \u0027/zh-cn/library/bb249818(l=zh-cn,v=office.12).aspx\u0027;\n var wt_nvr_ru = \u0027WT_NVR_RU\u0027;\n var wt_fpcdom = \u0027.microsoft.com\u0027;\n var wt_domlist = \u0027msdn.microsoft.com\u0027;\n var wt_pathlist = \u0027\u0027;\n var wt_paramlist = \u0027DCSext.mtps_devcenter\u0027;\n var wt_siteid = \u0027MSDN\u0027;\n var gDomain = \u0027m.webtrends.com\u0027;\n var gDcsId = \u0027dcsmgru7m99k7mqmgrhudo0k8_8c6m\u0027;\n var gFpc = \u0027WT_FPC\u0027;\n\n\n\n if (document.cookie.indexOf(gFpc + \"=\") == -1) {\n var wtidJs = document.createElement(\"script\");\n wtidJs.src = http://www.mamicode.com/"//\" + gDomain + \"/\" + gDcsId + \"/wtid.js\";\n document.getElementsByTagName(\"head\")[0].appendChild(wtidJs);\n }\n\n\n\n var detectedLocale = \u0027zh-cn\u0027;\n var wtsp = \u0027msdnlib_office\u0027;\n var gTrackEvents = \u00270\u0027;\n/**/" }, { txt: "/**/\n var omni_guid = \"3d2a52ee-7a0d-4c9c-bf4e-2e2c17a640b8\";\n/**/" }, { txt: "//\n\n window.appInsightsId = \u002760854590-027a-4ae4-98be-2741a40f355f\u0027;\n //" }, { url: "http://i2.msdn.microsoft.com/Combined.js?resources=0:Utilities,1:Layout,2:Header,3:FeedbackCounterAsync,1:Rating,2:Footer,0:Topic,4:webtrendsscript,5:omni_rsid_MSDN,0:AppInsightsPerf,6:Toc,1:SearchBox;/Areas/Epx/Content/Scripts:0,/Areas/Epx/Themes/Base/Content:1,/Areas/Centers/Themes/StandardDevCenter/Content:2,/Areas/Epx/Shared/Content:3,/Areas/Global/Content/Webtrends/resources:4,/Areas/Global/Content/Omniture/resources/MSDN:5,/Areas/Library/Content:6\u0026amp;hashKey=6FECEFF0725E63998BB59ED16B89B2E7" }, { url: "http://i1.services.social.microsoft.com/search/Widgets/SearchBox.jss?boxid=HeaderSearchTextBox\u0026btnid=HeaderSearchButton\u0026brand=Msdn\u0026loc=zh-cn\u0026focusOnInit=false\u0026emptyWatermark=true\u0026searchButtonTooltip=搜索 MSDN" }, { url: "http://i2.msdn.microsoft.com/Combined.js?resources=0:PrintExportButton,1:NavigationResize;/Areas/Library/Themes/Base/Content:0,/Areas/Library/Content:1\u0026amp;hashKey=72684789A0F98A77C33C1AC3470E9ECF" }, { txt: "MTPS = window.MTPS || {}; MTPS.LocalizedStrings = window.MTPS.LocalizedStrings || {}; MTPS.LocalizedStrings.ExpandButtonTooltip = \u0027展开\u0027; MTPS.LocalizedStrings.CollapseButtonTooltip = \u0027折叠\u0027; MTPS.LocalizedStrings.EnhancedExpandTooltip = \u0027单击以展开。双击以全部展开。\u0027; MTPS.LocalizedStrings.EnhancedCollapseTooltip = \u0027单击以折叠。双击以全部折叠。\u0027; MTPS.LocalizedStrings.ExpandAllButtonTooltip = \u0027全部展开\u0027; MTPS.LocalizedStrings.CollapseAllButtonTooltip = \u0027全部折叠\u0027;" }, { url: "http://i2.msdn.microsoft.com/Combined.js?resources=0:LibraryMemberFilter,1:Toc_Fixed,1:CodeSnippet,1:TopicNotInScope,1:CollapsibleArea,1:VersionSelector,1:SurveyBroker;/Areas/Library/Content:0,/Areas/Epx/Content/Scripts:1\u0026amp;hashKey=BA0D41FD888DE12A388DAF9CAC70144D" }, { txt: "$(document).ready(function() {\n try {\n var token = $(\"#globalRequestVerification input[name=\u0027__RequestVerificationToken\u0027]\").clone();\n $(\"#siteFeedbackForm\").append(token);\n } catch(err) {\n \n }\n });" }]);// ]]></script>
Sharepoint CAML 增删改查 List