Powershell 和 sharepoint 以及 updatelistitems() 异常

Powershell 和 sharepoint 以及 updatelistitems() 异常

我遇到了一个问题,我总是

"Exception calling "UpdateListItems" with "2" argument(s): "Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown."

每当我调用 时$service.updatelistitems($listname, $xml)。我在网上搜索过,发现有些人有类似的问题。我的 SharePoint 列表称为 Autos,并将字段Title重命名为Make,并附加一个字段名称Model,这两个都是简单的字符串字段。

有人知道为什么我无法更新我的列表吗?阅读列表没问题。

    $uri = 'http://myServerName/sandbox/_vti_bin/lists.asmx?wsdl'
    $listName = 'Autos'  # car list
    cls

    # Create the service            
    $service = New-WebServiceProxy -Uri $uri  -Namespace SpWs  -UseDefaultCredential

    # Create xml query to retrieve list.
    $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

    try{
        $service = New-WebServiceProxy -Uri $uri  -Namespace SpWs  -UseDefaultCredential
    }
    catch{
        Write-Error $_ -ErrorAction:'SilentlyContinue'
    }

    # Now, we use the service object to retrieve the list.
    if($service -ne $null){
        try{
            $list = $service.GetListItems($listName, "", $query, $viewFields, $rowLimit, $queryOptions, "")
        }
        catch{
            Write-Error $_ -ErrorAction:'SilentlyContinue'
        }
    }

    # $list.data.row
    ($list.data.row).count


    # 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") # Capital B
    $batchelement.setattribute("onerror", "continue")
    $batchelement.setattribute("listversion", "1")
    $batchelement.setattribute("viewname", $strviewid)

    # Specify methods for the batch post using caml. to update or delete, specify the id of the item,
    # and to update or add, specify the value to place in the specified column
    $xml = ""
    $xml += "<method ID='1' cmd='Update'>" +
            "<field name='ID'>1</field>" +
            "<field name='Title'>Subaru</field>" +
            "<field name='Model'>Outback</field>" +
            "</method>"


    # Set the xml content
    $batchelement.innerxml = $xml

    $ndreturn = $null
    # $ndreturn = $service.updatelistitems($strlistid, $batchelement) # no change using listID
            $ndreturn = $service.updatelistitems($listName, $batchelement)

相关内容