PowerShell调用SharePoint web service遍历/修改List(列表)数据
2012-11-13 17:43
405 查看
昨天在检测一段PowerShell代码,调用SharePoint List Web Servicel来查看List items,修改一个List item值时,总是报错,前后检查一个多小时,都没有发现错误原因, 今天早上来一看,才发现,是因为batch file内容的"Cmd='Update'",被我不小心写成了"cmd='Update'", 因为一个字母的大小写,纠结了一个多小时,拿出来跟大家分享一下:
代码:
如果xml 大小写有问题的话,扑捉异常后,就会有exception:
Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.
没有扑捉异常的情况下,exception:
Exception calling "UpdateListItems" with "2" argument(s): "Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown."
At line:72 char:37
+ $ndreturn = $service.UpdateListItems <<<< ($strlistid, $batchelement)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
代码:
#test update list item using web service $uri = 'http://v-qiwei:100/site1/_vti_bin/lists.asmx?wsdl' $listName = 'List_11' #the list name in the site # define query object to retrieve list items. $xmlDoc = new-object System.Xml.XmlDocument $query = $xmlDoc.CreateElement("Query") $viewFields = $xmlDoc.CreateElement("ViewFields") $queryOptions = $xmlDoc.CreateElement("QueryOptions") $query.set_InnerXml("FieldRef Name='Full Name'") $rowLimit = "1000" $list = $null $service = $null #create service object try{ $service = New-WebServiceProxy -Uri $uri -Namespace SpWs -UseDefaultCredential } catch [Exception] { return $_.Exception.Message } # use the service object to retrieve the list. if($service -ne $null){ try{ $list = $service.GetListItems($listName, "", $query, $viewFields, $rowLimit, $queryOptions, "") } catch [Exception] { return $_.Exception.Message } } # check the retrieved list item ($list.data.row).count # Get Guids of the list the view $ndlistview = $service.getlistandview($listname, "") $strlistid = $ndlistview.childnodes.item(0).name $strviewid = $ndlistview.childnodes.item(1).name write-host $strlistid write-host $strviewid # Create an xmldocument objec $xmldoctest = new-object system.xml.xmldocument # create a batch file $batchelement = $xmldoctest.CreateElement("Batch") $batchelement.SetAttribute("OnError","Continue") $batchelement.SetAttribute("ListVersion","1") $batchelement.SetAttribute("ViewName",$strviewid) $xml = "" $xml+="<Method ID='1' Cmd='Update'>"+ "<Field Name='ID'>1</Field>"+ "<Field Name='Title'>TestTitle</Field>"+ "</Method>" # Set the xml content $batchelement.innerxml = $xml write-host $batchelement.innerxml try{ $service.UpdateListItems($strlistid, $batchelement) } catch [Exception] { return $_.Exception.Message }
如果xml 大小写有问题的话,扑捉异常后,就会有exception:
Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.
没有扑捉异常的情况下,exception:
Exception calling "UpdateListItems" with "2" argument(s): "Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown."
At line:72 char:37
+ $ndreturn = $service.UpdateListItems <<<< ($strlistid, $batchelement)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
相关文章推荐
- 方维分享系统模板修改,book_share_list.htm调用用户数据,$_FANWE['user']的数据
- 列表(list)和字典(dict)数据排序 Python
- Solr的学习使用之(六)获取数据列表-SolrDocumentList
- 解决WinForm中ComboBox控件的“设置"DataSourse”属性后无法修改项集合”以及两个不相关联的ComboxBox控件实现数据列表显示不可实现的问题
- DWZ 用dialog调用MVC自动生成的密码修改页面一直出现“数据加载中,请稍等...”和去掉“数据加载中,请稍等”的方法
- 数据List刷新UI的Items显示(比如服务器给客户端刷新好友列表) 方法(1)
- python中列表(list)和字典(dict)数据排序
- Redis数据类型--List(列表)
- 调用play的jpa查询数据时添加Transformers.ALIAS_TO_ENTITY_MAP可将结果集封装到list<map>对象里
- java中list列表转为json数据的方法
- C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- MFC 当列表控件为Report报表形式时,怎样实现修改表格数据
- 列表List的异常数据问题排查思路
- 链路状态路由协议,调用分发列表的时候,作用分析,distribute-list
- Java:集合,对列表(List)中的数据(整型、字符串、日期等)进行排序(正序、倒序)的方法;字符串按照整型排序的方法
- channelartlist循环调用顶级栏目和子栏目,修改可以获取外部链接
- oracle创建定时job,job调用存储过程,批量查询,批量修改,自定义数据类型,
- 织梦使用{dede:listsql}标签调用数据并实现静态分页
- C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- 5-Python3从入门到实战—基础之数据类型(列表-List)