InvalidOperationException when using Writer for Repeating Table - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

InvalidOperationException when using Writer for Repeating Table

Last post 05-26-2011 07:55 AM by JoanneWellings. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 05-26-2011 04:12 AM

    InvalidOperationException when using Writer for Repeating Table

    Hello - I am adding rows to a repeating table and filling it with data from a SharePoint list. I have this working correctly with one table on my form, but I'm getting an error when I repeat the procedure for another table. I am getting an "InvalidOperationException" on Writer.close()

     My code is:

    Public Sub Add_Control_Measures()

    'Retrieve a reference to the Main DOM

    Dim tabRoot As XPathNavigator = MainDataSource.CreateNavigator()

    ' Count the amount of group2 nodes

    Dim iter As XPathNodeIterator = tabRoot.Select("//my:myFields/my:Control_Measures", NamespaceManager)

    Dim group2NodesCount As Integer = iter.Count

    If iter.Count > 0 Then

     

    ' Retrieve the first group2 node

    Dim firstGroup2NodeNav As XPathNavigator = tabRoot.SelectSingleNode("//my:myFields/my:Control_Measures[1]", NamespaceManager)

    ' Retrieve the last group2 node

    Dim lastGroup2NodeNav As XPathNavigator = tabRoot.SelectSingleNode("//my:myFields/my:Control_Measures[" & group2NodesCount.ToString() & "]", NamespaceManager)

    ' Delete the range of nodes from the first to the last group2 nodes

    firstGroup2NodeNav.DeleteRange(lastGroup2NodeNav)

    End If

     

    ' string to hold the type of risk assessment that the user has chosen

    Dim strTypeAssessmentDD As String = MainDataSource.CreateNavigator().SelectSingleNode("//my:myFields/my:Type_of_Risk_Assessment", NamespaceManager).Value

    ' string to add control measure

    Dim strConMes As String

    Dim domNav As XPathNavigator = Me.DataSources("Risk Assessment Control Measures").CreateNavigator()

    Dim rows As XPathNodeIterator = domNav.Select("/dfs:myFields/dfs:dataFields/dfs:Risk_Assessment_Control_Measures", NamespaceManager)

    Dim strTypeAssessment As String

     

    While rows.MoveNext() strTypeAssessment = rows.Current.SelectSingleNode("@Type_of_Risk_Assessment", NamespaceManager).Value

    'if the row matches the type of risk assessment, then add row to the array

    If strTypeAssessment = strTypeAssessmentDD Then

    strConMes = rows.Current.SelectSingleNode("@Control_Measure", NamespaceManager).Value

    Dim xname As String = NamespaceManager.LookupNamespace("my")

    Using CMwriter As XmlWriter = MainDataSource.CreateNavigator().SelectSingleNode("//my:myFields", NamespaceManager).AppendChild()

    CMwriter.WriteStartElement("Control_Measures", xname)

    CMwriter.WriteElementString("Control_Measure", xname, strConMes)CMwriter.WriteElementString("Score", xname, "")

    CMwriter.WriteEndElement()

    CMwriter.Close()

    End Using

    End If

    End While

    End Sub

    I've debugged it as far as I can. everything seems to be correct. I've tried sending just an empty string to "CMwriter.WriteElementString("Control_Measure", xname, strConMes)" and I get the same error. As I said, this works elsewhere with a different table and a different list on the same form. Can anyone see what the problem is, or what else I can try? Many thanks

  • 05-26-2011 07:55 AM In reply to

    Re: InvalidOperationException when using Writer for Repeating Table

    Solved it!

    I had to create another sub folder to put my repeating table in.

    Instead of  "//my:myFields/my:Control_Measures", I changed it to "//my:myFields/my:CM_Repeat/my:Control_Measures"

    This is strange, because for the first list I got working, I didn't need to do that.

    As soon as I implemented the above for the second list, the first stopped working and I had to do the same thing to make it work again. Very strange!

    I hope someone else finds this useful...

Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.