One quick tip for those trying to code SOAP services using VB. On Office 2007 and newer, you'll need to use the MSSOAP30.DLL library which means changing the new object call from:
CreateObject("MSSOAP.SOAPClient")
to:
CreateObject("MSOSOAP.SOAPClient30")
Because this returns an IXMLDOMSelection object, you also no longer need to specify the .childnodes member. So the general purpose script now looks like this:
Dim xmlDoc, SOAPClient, siteRoot
siteRoot = "http://sharepoint"
Set xmlDoc = CreateObject("MSXML2.DOMDocument.5.0")
xmlDoc.async = False
xmlDoc.loadXML( _
"<Document>" + _
" <Query><Where><Gt><FieldRef Name=""ID"" />" + "<Value
Type=""Counter"">1</Value></Gt></Where></Query>" + _
" <ViewFields/>" + _
" <QueryOptions/>" + _
"</Document>")
Set SOAPClient = CreateObject("MSOSOAP.SOAPClient30")
SOAPClient.mssoapinit siteRoot & "/_vti_bin/Lists.asmx?WSDL"
Dim result
Set result = SOAPClient.GetListItems( "Tasks", "", _
xmlDoc.getElementsByTagName("Query"), _
xmlDoc.getElementsByTagName("ViewFields"), "", _
xmlDoc.getElementsByTagName("QueryOptions"), "" )
DisplayNode result
' =================== 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
' change DisplayAttrs_(xNode, Indent + 2) to
' DisplayAttrs_(xNode, 0) for inline attributes
WScript.Echo strDup(" ", Indent) & "<" & xNode.nodeName & _
DisplayAttrs_(xNode, Indent + 2) & ">"
If xNode.hasChildNodes Then
DisplayNode_ xNode.childNodes, Indent + 2
End If
WScript.Echo strDup(" ", Indent) & "</" & xNode.nodeName & ">"
Else
If xNode.hasChildNodes Then
DisplayNode_ xNode.childNodes, Indent + 2
End If
End If
Case 3: ' NODE_TEXT
WScript.Echo strDup(" ", Indent) & xNode.nodeValue
End Select
Next
End Sub
Function DisplayAttrs_(Node, Indent)
Dim xAttr, res
res = ""
For Each xAttr In Node.attributes
If Indent = 0 Then
res = res & " " & xAttr.name & "=""" & xAttr.value & """"
Else
res = res & vbCrLf & strDup(" ", Indent) & xAttr.name & _
"=""" & xAttr.value & """"
End If
Next
DisplayAttrs_ = res
End Function
Function strDup(dup, c)
Dim res, i
res = ""
For i = 1 To c
res = res & dup
Next
strDup = res
End Function
Happy coding!
Comments
VBA/VBScript and SharePoint Document Library
I really need some help here and your site so far has given me the best information, but I'm still stuck. I'm trying to figure out how to programatically upload files from a local machine to a SharePoint document library using VBScript. Unfortunately everything I've found so far talks about working with SharePoint lists (not document libraries) and suggests using a different coding language/program (which I don't have a choice about--have to use VBScript). I've confirmed my SharePoint list has the "CopyIntoItems" SOAP method available, which I think is what I have to use. I just can't figure out the code (in VBS) to establish the connection and upload a file. Any help would be greatly appreciated.