我目前正在尝试使用lists.asmx更新SharePoint列表。不幸的是,我无法使用CSOM,因为这将作为批处理文件传递给非技术人员。我在将新项目添加到列表时已经工作了,但如果我修改代码以更新列表中的项目,则不会更新任何项目。
代码如下:
# Connect to web service
$uri = "http://teams.COMPANY.intranet/_vti_bin/lists.asmx"
$service = New-WebServiceProxy -uri $uri -Namespace SpWs -UseDefaultCredential # -credential $credential
$service.url = "http://home.COMPANY.intranet/sites/Sharepoint/_vti_bin/lists.asmx"
$xmlDoc = new-object System.Xml.XmlDocument
$listName = "MapDetails"
$viewFields = $xmlDoc.CreateElement("ViewFields")
$query = $xmlDoc.CreateElement("Query")
# Get name attribute values (guids) for list and view
$ndlistview = $service.getlistandview($listname, "")
$strlistid = $ndlistview.childnodes.item(0).name
$strviewid = $ndlistview.childnodes.item(1).name
# Create an xmldocument object and construct a batch element and its attributes.
$xmldoc = new-object system.xml.xmldocument
# note that an empty viewname parameter causes the method to use the default view
$batchelement = $xmldoc.createelement("Batch")
$batchelement.setattribute("onerror", "continue")
$batchelement.setattribute("listversion", "1")
$batchelement.setattribute("viewname", $strviewid)
$id = 1
$xml = ""
# The row to be modified
$rowId = 0
$Files=GET-CHILDITEM '\\Client.COMPANY.com\Homeshare\HOME0029\USER\My Documents\WebTrends Global Adoption\Output\*.txt' | Sort-Object
Foreach ($File in $Files) {
$fullName = $File.BaseName
$content = Get-Content $File
$xml = "<Method ID='$id' Cmd='Update'>" +
"<Field Name='ID'>$rowId</Field>" +
"<Field Name='Title'>$fullName</Field>" +
"<Field Name='LocationDetails'><![CDATA[$content]]></Field></Method>"
# Set the xml content
$batchelement.innerxml = $xml
$ndreturn = $null
$ndreturn = $service.updatelistitems($listname, $batchelement)
$rowId++
}
我已经在网上搜索了解决方案,但似乎找不到任何有同样问题的人。也许我只是愚蠢。如果以前发布过这个问题,请随意指出正确的方向。
谢谢!