Looping through seconday datasource from SharePoint library or list - InfoPath Dev
in

InfoPath Dev

Looping through seconday datasource from SharePoint library or list

Last post 07-12-2010 08:28 AM by Jimmy. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 07-10-2010 01:47 PM

    Looping through seconday datasource from SharePoint library or list

     I am new to InfoPath and just need help getting the data from our Sharepoint where I can loop through the records using C# code. I have been looking at all kinds of documents and form posts, but just can't seem to get it. Can someone please help me get this data? I have tried a ton more than this code, just cant seem to get it :-(

     

    Code I am trying (but it only returns 1 record when I know there are multiple records)

                 XPathNavigator domNav = this.DataSources["AuditLog"].CreateNavigator();
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(domNav.NameTable);
                nsmgr.AddNamespace("dfs", "http://schemas.microsoft.com/office/infopath/2003/dataFormSolution");
                XPathNodeIterator xNode = domNav.Select("/dfs:myFields/dfs:dataFields", nsmgr);

                // The count is only returning one record when there are multiple records
                MessageBox.Show("We have " + xNode.Count.ToString() + " records");
                foreach (XPathNavigator xNode2 in xNode)
                {
                    MessageBox.Show(xNode2.InnerXml.ToString()); // This doesnt return anything
                    MessageBox.Show(xNode2.LocalName); // This returns "dataFields"
                    MessageBox.Show(xNode2.Name); // This returns "dfs:dataFields"
                    MessageBox.Show(xNode2.OuterXml.ToString()); // This doesnt return anything
                    MessageBox.Show(xNode2.NameTable.ToString()); // This returns "System.xml.NameTable"
                }

    XML from the Data Source

     <dfs:myFields xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution">
    <dfs:dataFields>
    <dfs:AuditLog Title="somefile.xml" Account_Name="My Name" />
    <dfs:AuditLog Title="anotherfile.xml" Account_Name="Another Name"/>
    </dfs:dataFields>
    </dfs:myFields>

  • 07-10-2010 09:22 PM In reply to

    Re: Looping through seconday datasource from SharePoint library or list

    The XPath should be "/dfs:myFields/dfs:dataFields/dfs:AuditLog".  There is only one dfs:dataFields node.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 07-12-2010 08:20 AM In reply to

    Re: Looping through seconday datasource from SharePoint library or list

    Thanks so much for the reply, that is what I was looking for. Now last question and I think I should be good to go.

    If I display the output of the below line, I see

    <dfs:AuditLog xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" Title="somefile.xml" Account_Name="My Name" />

    how can I get the value of Title? I tried something like xNode2.OuterXml[3].ToString() but is didnt return the correct results, and couldnt figure out any other value to call.

     

    XPathNavigator domNav = this.DataSources["AuditLog"].CreateNavigator();

    XmlNamespaceManager nsmgr = new XmlNamespaceManager(domNav.NameTable);

    nsmgr.AddNamespace("dfs", "http://schemas.microsoft.com/office/infopath/2003/dataFormSolution");

    XPathNodeIterator xNode = domNav.Select("/dfs:myFields/dfs:dataFields/dfs:AuditLog", nsmgr);

    // The count is only returning one record when there are multiple records

    MessageBox.Show("We have " + xNode.Count.ToString() + " records");foreach (XPathNavigator xNode2 in xNode)

    {

    MessageBox.Show(xNode2.OuterXml.ToString()); // This returns <dfs:AuditLog xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" Title="somefile.xml" Account_Name="My Name" />

    }

  • 07-12-2010 08:28 AM In reply to

    Re: Looping through seconday datasource from SharePoint library or list

    xNode2.SelectSingleNode("@Title").Value

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.