Creating SharePoint list item with vbscript and WebServices
Few days back I had some urgent requirement to create and update a sharepoint list item using vbscript and sharepoint WebServices. After goggling a bit i found a solution in one of the msdn forums .. so posting the code here with my additions
Code :
Sub AddListItem(site, listGUID, itemTitle)
strEndPointURL = "http://moss" + site + "/_vti_bin/Lists.asmx"
strSoapAction="http://schemas.microsoft.com/sharepoint/soap/UpdateListItems"
Set objSOAPConnector = CreateObject("MSOSOAP.HttpConnector30")
with objSOAPConnector
.Property("EndPointURL") = strEndPointURL
.Property("SoapAction") = strSoapAction
.Connect
End With
Set objSOAPSerializer = CreateObject("MSOSoap.SoapSerializer30")
with objSOAPSerializer
.Init(objSOAPConnector.InputStream)
.startEnvelope()
.startBody()
.StartElement "UpdateListItems", "http://schemas.microsoft.com/sharepoint/soap/"
.StartElement "listName", "http://schemas.microsoft.com/sharepoint/soap/"
.WriteString(listGUID)
.EndElement()
.StartElement "updates","http://schemas.microsoft.com/sharepoint/soap/"
.StartElement "Batch"
.SoapAttribute "ListName", ,listGUID
.SoapAttribute "OnError", ,"Continue"
.StartElement "Method"
.SoapAttribute "ID", ,"1"
.SoapAttribute "Cmd", ,"New"
.StartElement "Field"
.SoapAttribute "Name", ,"Title"
.WriteString(itemTitle)
.EndElement()
.EndElement()
.EndElement()
.EndElement()
.EndElement()
.endBody()
.endEnvelope()
End With
objSOAPConnector.EndMessage()
Set objResponseReader = CreateObject("MSOSOAP.SoapReader30")
objResponseReader.Load(objSOAPConnector.OutputStream)
Wscript.echo objResponseReader.Body.xml
End Sub
Code :
Sub AddListItem(site, listGUID, itemTitle)
strEndPointURL = "http://moss" + site + "/_vti_bin/Lists.asmx"
strSoapAction="http://schemas.microsoft.com/sharepoint/soap/UpdateListItems"
Set objSOAPConnector = CreateObject("MSOSOAP.HttpConnector30")
with objSOAPConnector
.Property("EndPointURL") = strEndPointURL
.Property("SoapAction") = strSoapAction
.Connect
End With
Set objSOAPSerializer = CreateObject("MSOSoap.SoapSerializer30")
with objSOAPSerializer
.Init(objSOAPConnector.InputStream)
.startEnvelope()
.startBody()
.StartElement "UpdateListItems", "http://schemas.microsoft.com/sharepoint/soap/"
.StartElement "listName", "http://schemas.microsoft.com/sharepoint/soap/"
.WriteString(listGUID)
.EndElement()
.StartElement "updates","http://schemas.microsoft.com/sharepoint/soap/"
.StartElement "Batch"
.SoapAttribute "ListName", ,listGUID
.SoapAttribute "OnError", ,"Continue"
.StartElement "Method"
.SoapAttribute "ID", ,"1"
.SoapAttribute "Cmd", ,"New"
.StartElement "Field"
.SoapAttribute "Name", ,"Title"
.WriteString(itemTitle)
.EndElement()
.EndElement()
.EndElement()
.EndElement()
.EndElement()
.endBody()
.endEnvelope()
End With
objSOAPConnector.EndMessage()
Set objResponseReader = CreateObject("MSOSOAP.SoapReader30")
objResponseReader.Load(objSOAPConnector.OutputStream)
Wscript.echo objResponseReader.Body.xml
End Sub
It 's an amazing and Very Nice,Thanks for sharing
ReplyDeleteDot Net Online Training Hyderabad