Please help! Can't get simple form (msdn example) to work - InfoPath Dev
in

InfoPath Dev

Please help! Can't get simple form (msdn example) to work

Last post 08-01-2011 03:39 PM by Josee Sevigny. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 07-26-2011 07:28 AM

    Please help! Can't get simple form (msdn example) to work

     I am trying to get this example to work first, so I can create a production form.  I followed these MSDN instructions to a T.  http://msdn.microsoft.com/en-us/library/cc162745%28v=office.12%29.aspx#ip2007SubmitDataSPList_AddingFieldsandControlsforSubmittingNewItemstotheList

     

    First time, I got the following errors on the Checkbox when checking it:

    System.Security.SecurityException
    Request failed.
       at Microsoft.Office.InfoPath.MsxmlNavigator.IsValidNode(MsxmlNode test)
       at Microsoft.Office.InfoPath.MsxmlNavigator.MoveToFirstChild()
       at MS.Internal.Xml.XPath.XPathChildIterator.MoveNext()
       at MS.Internal.Xml.XPath.ChildrenQuery.Advance()
       at MS.Internal.Xml.XPath.ChildrenQuery.Advance()
       at MS.Internal.Xml.XPath.XPathSelectionIterator.MoveNext()
       at System.Xml.XPath.XPathNavigator.SelectSingleNode(XPathExpression expression)
       at System.Xml.XPath.XPathNavigator.SelectSingleNode(String xpath, IXmlNamespaceResolver resolver)
       at Template1.FormCode.AddItem_Changed(Object sender, XmlEventArgs e)
       at Microsoft.Office.InfoPath.Internal.XmlEventHost.GenericProxy(Object genericDelegate, DataDOMEvent dataDOMEvent, InfoPathEvents type)
       at Microsoft.Office.InfoPath.Internal.XmlEventHost.ChangedProxy(DataDOMEvent dataDOMEvent)
       at Microsoft.Office.Interop.InfoPath.SemiTrust._DataDOMEventSink_SinkHelper.OnAfterChange(DataDOMEvent pDataDOMEvent)

     

    So, I changed the Security to Full Trust, then get the following errors:

    When I check the Add Contacts checkbox:

    System.InvalidOperationException
    Schema validation found non-data type errors.
       at Microsoft.MsoOffice.InfoPath.MsxmlInterop.MsxmlDocument.ThrowExceptionFromMsxmlInteropError(MsxmlInteropError eError)
       at Microsoft.MsoOffice.InfoPath.MsxmlInterop.MsxmlDocument.ThrowExceptionFromHresult(Int32 hrError)
       at Microsoft.MsoOffice.InfoPath.MsxmlInterop.MsxmlNodeImpl.AppendChild(String strXml)
       at Microsoft.Office.InfoPath.MsxmlWriter.Close()
       at System.Xml.XmlWellFormedWriter.Close()
       at System.Xml.XPath.XPathNavigator.AppendChild(XmlReader newChild)
       at System.Xml.XPath.XPathNavigator.AppendChild(String newChild)
       at Template5.FormCode.AddContacts_Changed(Object sender, XmlEventArgs e)
       at Microsoft.Office.InfoPath.Internal.XmlEventHost.GenericProxy(Object genericDelegate, DataDOMEvent dataDOMEvent, InfoPathEvents type)
       at Microsoft.Office.InfoPath.Internal.XmlEventHost.ChangedProxy(DataDOMEvent dataDOMEvent)
       at Microsoft.Office.Interop.InfoPath.SemiTrust._DataDOME

     

    And after pressing OK on the error above, I type in a new contact and press the Submit button and get the following error:

     System.NullReferenceException
    Object reference not set to an instance of an object.
       at Template5.FormCode.btnSendChanges_Clicked(Object sender, ClickedEventArgs e)
       at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
       at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)


  • 07-26-2011 03:26 PM In reply to

    Re: Please help! Can't get simple form (msdn example) to work

    So, your instinct to change to full trust was correct, since you were getting a security exception. But I don't think the code from this sample will require full trust on publication - does your machine belong to a domain? Sometimes that causes issues with domain trust in preview (if you don't belong to a domain).

    What's the code on the field bound to your checkbox? What's the code on your submit button? I know, you've followed a sample, but didn't quickly see the event code for the checkbox.

    The first error (after the security error) is most likely because a field needs to have the nil attribute added or removed. The last error - could be anything. That's why it would help to see your code.

    Hilary Stoupa

  • 07-26-2011 03:42 PM In reply to

    Re: Please help! Can't get simple form (msdn example) to work

    Thank you The code for the checkbox is: Try ' Get a reference to the form's XmlNamespaceManager object. Dim ns As XmlNamespaceManager = Me.NamespaceManager ' Create an XPathNavigator object for the form's main data ' source. Dim xnDoc As XPathNavigator = Me.MainDataSource.CreateNavigator() ' If the check box is set to true, add a new row so the user ' can add a new contact. If e.Site.Value = "true" Then Dim xnTable As XPathNavigator = xnDoc.SelectSingleNode("/my:myFields/my:gpContacts", ns) xnTable.AppendChild("") Else ' If the user clears the check box, remove the added row. ClearEnteredValues(xnDoc) End If Catch ex As Exception MessageBox.Show("The following error occurred: " + ex.Message) Throw End Try This is the code for the Cleared Event (for the checkbox) Private Sub ClearEnteredValues(xnDoc As XPathNavigator) Try ' Get a reference to the form's XmlNamespaceManager object. Dim ns As XmlNamespaceManager = Me.NamespaceManager ' Create an XPathNodeIterator object to get a count of the ' rows in the repeating table used to add new Contacts. Dim xi As XPathNodeIterator = xnDoc.[Select]("/my:myFields/my:gpContacts/my:gpContact", ns) Dim rowCount As Integer = xi.Count If rowCount > 0 Then ' Get the first and last rows (nodes) in the ' repeating table. Dim firstNode As XPathNavigator = xnDoc.SelectSingleNode("/my:myFields/my:gpContacts/my:gpContact[1]", ns) Dim lastNode As XPathNavigator = xnDoc.SelectSingleNode("/my:myFields/my:gpContacts/my:gpContact[" & rowCount & "]", ns) ' Delete the existing nodes using the DeleteRange method. firstNode.DeleteRange(lastNode) End If ' Clear the check box. xnDoc.SelectSingleNode("/my:myFields/my:AddContacts", ns).SetValue("false") Catch ex As Exception MessageBox.Show("The following error occurred: " + ex.Message) Throw End Try End Sub This is the code for the Submit button Try ' Get a reference to the form's XmlNamespaceManager object. Dim ns As XmlNamespaceManager = Me.NamespaceManager ' Create a DataSource object for the MyContacts ' list data connection. Dim dsContacts As DataSource = Me.DataSources("MyContacts") ' Create an XPathNavigator object for the MyContacts ' data connection. Dim xnContacts As XPathNavigator = dsContacts.CreateNavigator() ' Create an XPathNodeIterator object for the MyContacts ' data connection to enumerate the existing contacts. Dim xiContacts As XPathNodeIterator = xnContacts.[Select]("/dfs:myFields/dfs:dataFields/dfs:MyContacts", ns) ' Create a DataSource object for the Add List Item Template ' data connection. Dim dsCAML As DataSource = Me.DataSources("Add List Item Template") ' Create an XPathNavigator object for the ' Add List Item Template data connection. ' This is used to set the values in the CAML XML file. Dim xnCAML As XPathNavigator = dsCAML.CreateNavigator() ' Create a WebServiceConnection object for submitting ' to the Lists Web service data connection. Dim wsSubmit As WebServiceConnection = DirectCast(Me.DataConnections("Web Service Submit"), WebServiceConnection) ' Create an XPathNavigator object for the form's ' main data source. Dim xnDoc As XPathNavigator = Me.MainDataSource.CreateNavigator() ' Create an XPathNodeIterator object for the new contacts. Dim xiNewContacts As XPathNodeIterator = xnDoc.[Select]("/my:myFields/my:gpContacts/my:gpContact", ns) ' See if any new contacts have been added. If xiNewContacts.Count > 0 Then While xiNewContacts.MoveNext() ' Set the values in the Add List Item Template ' XML file using the values in the new row. xnCAML.SelectSingleNode("/Batch/Method/Field[@Name='Title']", ns).SetValue(xiNewContacts.Current.SelectSingleNode("my:Title", ns).Value) xnCAML.SelectSingleNode("/Batch/Method/Field[@Name='FirstName']", ns).SetValue(xiNewContacts.Current.SelectSingleNode("my:FirstName", ns).Value) xnCAML.SelectSingleNode("/Batch/Method/Field[@Name='LastName']", ns).SetValue(xiNewContacts.Current.SelectSingleNode("my:LastName", ns).Value) xnCAML.SelectSingleNode("/Batch/Method/Field[@Name='Phone']", ns).SetValue(xiNewContacts.Current.SelectSingleNode("my:Phone", ns).Value) xnCAML.SelectSingleNode("/Batch/Method/Field[@Name='Email']", ns).SetValue(xiNewContacts.Current.SelectSingleNode("my:Email", ns).Value) ' Set the values of the Changed and Delete columns to ' "FALSE". xnCAML.SelectSingleNode("/Batch/Method/Field[@Name='Changed']", ns).SetValue("FALSE") xnCAML.SelectSingleNode("/Batch/Method/Field[@Name='Delete']", ns).SetValue("FALSE") ' Set the value of Cmd attribute to "New". xnCAML.SelectSingleNode("/Batch/Method/@Cmd", ns).SetValue("New") ' Submit the new row. wsSubmit.Execute() End While Else ' Enumerate the existing contacts and see if ' any items have been changed or set to be deleted. While xiContacts.MoveNext() If xiContacts.Current.SelectSingleNode("@Changed", ns).Value = "true" Then ' Set the values in the Add List Item Template XML file ' to the values in the updated row. xnCAML.SelectSingleNode("/Batch/Method/Field[@Name='Title']", ns).SetValue(xiContacts.Current.SelectSingleNode("@Title").Value) xnCAML.SelectSingleNode("/Batch/Method/Field[@Name='FirstName']", ns).SetValue(xiContacts.Current.SelectSingleNode("@FirstName").Value) xnCAML.SelectSingleNode("/Batch/Method/Field[@Name='LastName']", ns).SetValue(xiContacts.Current.SelectSingleNode("@LastName").Value) xnCAML.SelectSingleNode("/Batch/Method/Field[@Name='Phone']", ns).SetValue(xiContacts.Current.SelectSingleNode("@Phone").Value) xnCAML.SelectSingleNode("/Batch/Method/Field[@Name='Email']", ns).SetValue(xiContacts.Current.SelectSingleNode("@Email").Value) xnCAML.SelectSingleNode("/Batch/Method/Field[@Name='Changed']", ns).SetValue("false") xnCAML.SelectSingleNode("/Batch/Method/Field[@Name='ID']", ns).SetValue(xiContacts.Current.SelectSingleNode("@ID").Value) ' Set the value of the Cmd attribute to "Update". xnCAML.SelectSingleNode("/Batch/Method/@Cmd", ns).SetValue("Update") ' Submit the updates for the current row. wsSubmit.Execute() End If ' If the Delete field is set to "true" for the current ' row, in the Batch fragment set the ID for the row ' and set the Cmd attribute to "Delete". If xiContacts.Current.SelectSingleNode("@Delete", ns).Value = "true" Then xnCAML.SelectSingleNode("/Batch/Method/Field[@Name='ID']", ns).SetValue(xiContacts.Current.SelectSingleNode("@ID").Value) xnCAML.SelectSingleNode("/Batch/Method/@Cmd", ns).SetValue("Delete") ' Submit the delete operation for the current row. wsSubmit.Execute() End If End While End If ' Create a DataConnection object for the MyContacts ' data connection. Dim dcContacts As DataConnection = Me.DataConnections("MyContacts") ' Execute the data connection to refresh the list of ' contacts to reflect any additions, updates, or deletions. dcContacts.Execute() ' Clear the values in the repeating table for ' adding new contracts. ClearEnteredValues(xnDoc) Catch ex As Exception MessageBox.Show("The following error occurred: " + ex.Message) Throw End Try Yes, domain. Thanks so much
  • 07-26-2011 04:00 PM In reply to

    Re: Please help! Can't get simple form (msdn example) to work

    I sent you an email asking you to email me your code, since I can't read it in a big block like this (sometimes it can be hard to get it to copy & paste nicely). You should also try running your project in debug to see the lines you are failing on. Here's a blog post on how to do that if you need help, okay?

    Hilary Stoupa

  • 08-01-2011 02:49 PM In reply to

    Re: Please help! Can't get simple form (msdn example) to work

    Hello

     I'm starting to get the same error while in Domain trust:

    System.Security.SecurityException
    Request failed.
       at Microsoft.Office.InfoPath.MsxmlNavigator.IsValidNode(MsxmlNode test)
       at Microsoft.Office.InfoPath.MsxmlNavigator.MoveToFirstChild()
       at MS.Internal.Xml.XPath.XPathDescendantIterator.MoveNext()
       at MS.Internal.Xml.XPath.DescendantQuery.Advance()
       at MS.Internal.Xml.XPath.CacheChildrenQuery.GetNextInput()
       at MS.Internal.Xml.XPath.CacheChildrenQuery.Advance()
       at MS.Internal.Xml.XPath.Query.MoveNext()
       at MS.Internal.Xml.XPath.Query.get_Count()
       at MS.Internal.Xml.XPath.XPathSelectionIterator.get_Count()
       at Leave_Request.FormCode.isApprover_attr_Changed(Object sender, XmlEventArgs e)
       at Microsoft.Office.InfoPath.Internal.XmlEventHost.GenericProxy(Object genericDelegate, DataDOMEvent dataDOMEvent, InfoPathEvents type)
       at Microsoft.Office.InfoPath.Internal.XmlEventHost.ChangedProxy(DataDOMEvent dataDOMEvent)
       at Microsoft.Office.Interop.InfoPath.SemiTrust._DataDOMEventSink_SinkHelper.OnAfterChange(DataDOMEvent pDataDOMEvent)

    This form has worked well form the past 8 months but suddenly started to fail when my client upgraded some of his users to Windows 7 Professional 64-bit. All users still on XP are working fine. Both types of uses are using InfoPath 2007 and the form loads in the client (filler form).

    On the other hand, I'm accessing the form through a direct connection to their network, using Windows 7 Enterprise 64-bit and I'm not getting the error. I'm using IP 2010 though but somehow don't think it's related.

    Any ideas would help as I don't think there's actually anything wrong with the code.

    Josée Sévigny
  • 08-01-2011 03:26 PM In reply to

    Re: Please help! Can't get simple form (msdn example) to work

    Hi:

    Are the machines that are failing updated w/ the latest Windows updates? This thread suggests .NET 3.5 as the issue, but I'm pretty sure that's been patched by now.... your instinct that it is a machine issue is correct, I think.

    Hilary Stoupa

  • 08-01-2011 03:39 PM In reply to

    Re: Please help! Can't get simple form (msdn example) to work

    After applying Office SP2, works like a charm. Thanks for the input.

    Josée Sévigny
Page 1 of 1 (7 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.