Remove Duplicates from XPathNodeIterator - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Remove Duplicates from XPathNodeIterator

Last post 06-30-2016 12:27 PM by ISUGraber. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 06-22-2016 07:28 AM

    Remove Duplicates from XPathNodeIterator

    I am creating an InfoPath 2013 form with C# to pull data from and upload data to SQL Server. As part of the process I had to create a "Select All" Checkbox for my reports list. However, if I use the "Select All" option and then commit the code I get a duplicate record entered. If I manually select all checkboxes I don't get any duplicates. I am brand new to InfoPath and C#. So please let me know if I'm missing anything. I am doing this with XPathNodeIterator. Is there a way to find and remove duplicates with xPath? This is where I'm grabbing the reports from the Multi Selection Box: XPathNodeIterator multirpt = root.Select("//my:Report_Name", NamespaceManager); //Report Name needs to reset each time a new facility is added. while (multirpt.MoveNext()) //multirpt is to loop through the selected reports to add them to the access table. {
  • 06-23-2016 01:54 PM In reply to

    Re: Remove Duplicates from XPathNodeIterator

     I'm guessing your code may have gotten cut off when you posted - can you try again, and maybe use IE for posting? Other browsers seem to cause formatting problems in posts. I generally use a foreach loop to go through repeating nodes - code samples can be found here.

    Hilary Stoupa

  • 06-30-2016 12:27 PM In reply to

    Re: Remove Duplicates from XPathNodeIterator

    Thanks for the reply. Is there a way I can get my code to come out in non-paragraph ways? I found the answer in the meantime or at least a workaround. This command gets rid of duplicates. // Selecting the multi box that contains all of the reports I want. XPathNodeIterator multirpt = root.Select("//my:Report_Name[not(. = preceding-sibling::item)]", NamespaceManager); //Report Name needs to reset each time a new facility is added. //[@Report_Name = preceding-sibling::image/@Report_Name] // Create a List to manage List multirptList = new List(); //Make sure said node is filled in . while (multirpt.MoveNext()) { string Rpt = multirpt.Current.Value; // add reports to list from above. multirptList.Add(Rpt); } // Finally get the Unique records. List unique = multirptList.Distinct().ToList();
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.