Hi Patrick,
I am using the sample example given in your book "Developing solutions with MS InfoPath" on Page # 296 and I am getting the following error message:
Object reference not set to an instance of an object.
at SubmitExample.SubmitExample.CreateTask(String strTitle, String strProject, String strIssueDate, String strIssueStatus) in C:\PIB2\Sample\SubmitExample\FormCode.vb:line 114
at SubmitExample.SubmitExample.CTRL3_5_OnClick(DocActionEvent e) in C:\PIB2\Sample\SubmitExample\FormCode.vb:line 131
at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)
Below is my code that I am using to insert a new list item in sharepoint list:
Public Function CreateTask(ByVal strTitle As String, ByVal strProject As String, ByVal strIssueDate As String, ByVal strIssueStatus As String) As Integer
Dim listName As String
Dim listservice As lists.Lists
Dim node As XmlDocument
Dim res As XmlNode
Dim resultError As XmlNode
Dim resultId As XmlNode
'listName = "{33533BB8-132E-4C92-BA97-5748C43F67BE}"
listservice = New lists.Lists
listservice.Credentials = System.Net.CredentialCache.DefaultCredentials
node = New XmlDocument
node.LoadXml("" _
+ "<Batch OnError='Continue' Listversion='1' xmlns=''>" _
+ " <Method ID='1' Cmd='New'>" _
+ " <Field Name='IssueTitle'>" + strTitle + "</Field>" _
+ " <Field Name='Project'>" + strProject + "</Field>" _
+ " <Field Name='IssueDate'>" + strIssueDate + "</Field>" _
+ " <Field Name='IssueStatus'>" + strIssueStatus + "</Field>" _
+ " </Method>" _
+ "</Batch>")
res = listservice.UpdateListItems("{9CA2107C-CD11-4CA0-8F3F-1921F49100EF}", node)
Dim nsmgr As XmlNamespaceManager
nsmgr = New XmlNamespaceManager(res.OwnerDocument.NameTable)
nsmgr.AddNamespace("s", "http://schemas.microsoft.com/sharepoint/soap")
nsmgr.AddNamespace("z", "#RowsetSchema")
resultError = res.SelectSingleNode("s:Result[@ID='1,New']/s:ErrorCode", nsmgr)
If (resultError Is Nothing Or Convert.ToInt32(resultError.InnerText, 16) <> 0) Then
Return 0
End If
resultId = res.SelectSingleNode("s:Result[@ID=""1,New""]/z:row/@ows_ID", nsmgr)
Return Integer.Parse(resultId.InnerText)
End Function
' The following function handler is created by Microsoft Office InfoPath. Do not
' modify the type or number of arguments.
<InfoPathEventHandler(MatchPath:="CTRL3_5", EventType:=InfoPathEventType.OnClick)> _
Public Sub CTRL3_5_OnClick(ByVal e As DocActionEvent)
' Write your code here.
Dim id As Integer
id = CreateTask(thisXDocument.DOM.selectSingleNode("/my:myFields/my:IssueTitle").text, thisXDocument.DOM.selectSingleNode("/my:myFields/my:Project").text, thisXDocument.DOM.selectSingleNode("/my:myFields/my:IssueDate").text, thisXDocument.DOM.selectSingleNode("/my:myFields/my:IssueStatus").text)
If (id = 0) Then
thisXDocument.UI.Alert("Failed to create task")
Else
thisXDocument.UI.Alert("Created task with ID " + id.ToString + ".")
End If
End Sub
Red bold is the line 114 where I am getting this error.
Any help is appreciated.
Thanks,