More on VBScript and SharePoint SOAP

In response to a question from a reader, Tim, this is a follow-up from an earlier article on SharePoint, SOAP and VBScript. This time, we'll look at how to do more complex calls to SharePoint web services in VBScript

Some web services in SharePoint require passing XML as parameters. Unfortunately, you can't pass an XML document, it has to be an XML node element, and this takes a bit of effort to construct in VBScript.

The example we'll use is making a call to GetListItems, which returns all items in a SharePoint library, optionally matching a query formatted using a special XML syntax.

SharePoint Web Services query

This VBScript code allows you to query and post just about any information to SharePoint using web services. There are two steps involved:

  1. Check the signature of the Web Service you want to invoke. For example, http://sharepoint/_vti_bin/Lists.asmx will give a list of all operations you can perform on SharePoint lists.
  2. Create a VBScript file with the following lines:

    Option Explicit
    Dim xmlDoc, SOAPClient
    ' Get the root element object
    Set SOAPClient = createobject("MSSOAP.SOAPClient")  

VBScript XML pretty print

I don't know if this would ever be useful to anyone, but anyway:

Option Explicit

Dim xmlDoc
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.async = False
xmlDoc.loadXML("<GetList><a><b attr=""5"">a node</b></a></GetList>")

DisplayNode xmlDoc.childNodes

' =================== Helper Routines ==================

Sub DisplayNode(Nodes)
  DisplayNode_ Nodes, 0
End Sub

Sub DisplayNode_(Nodes, Indent)
   Dim xNode
   For Each xNode In Nodes
      Select Case xNode.nodeType
        Case 1:   ' NODE_ELEMENT
          If xNode.nodeName <> "#document" Then  
Syndicate content