p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   Infopath (http://p2p.wrox.com/infopath-189/)
-   -   SharePoint as secondary data source (http://p2p.wrox.com/infopath/83571-sharepoint-secondary-data-source.html)

cooltechie May 7th, 2011 06:27 PM

SharePoint as secondary data source

I am using Infopath and what I am trying to do is : I have a repeating table that should get its data from a secondary data source. In this case, the secondary data source is a SharePoint List.

But, we cannot retrieve multiple items from a secondary data source and copy them into a repeating table in Main data Source.

So I am trying to achieve this through C# code. I am getting an "Invalid Operation Exception" . Can anyone help, where I am doing wrong?


public void InternalStartup()
            ((ButtonEvent)EventManager.ControlEvents["get_Items"]).Clicked += new ClickedEventHandler(get_Items_Clicked);

        public void get_Items_Clicked(object sender, ClickedEventArgs e)
            // Write your code here.
            XPathNavigator secDSNav = DataSources["mydatasource"].CreateNavigator();
            //Retrieve the rows of the secondary data sources.

      XPathNodeIterator rows = secDSNav.Select("/dfs:myFields/dfs:dataFields/dfs:Items",NamespaceManager);

      int counter = 1;

      while (rows.MoveNext())
          string title = GetValueOrEmptyString(rows.Current.SelectSingleNode("@Field1", NamespaceManager));

          string status = GetValueOrEmptyString(rows.Current.SelectSingleNode("@Field2", NamespaceManager));

          DateTime myDate = GetValueOrEmptyString(rows.Current.SelectSingleNode("@Field3", NamespaceManager));

          // Increment the counter


          // Add the item to the repeating table

          AddItem(title, status, myDate);


      // Remove the first empty item from the repeating table


        public static string GetValueOrEmptyString(XPathNavigator node)
            return node == null ? string.Empty : node.Value;

        private void AddItem(string title, string status, DateTime mydate)

            XmlDocument doc = new XmlDocument();
            XmlNode group = doc.CreateElement("p:Item", "http://www.xxxx.com/myform/2009");
            XmlNode field = doc.CreateElement("p:Field1", "http://www.xxxx.com/myform/2009");
            XmlNode node = group.AppendChild(field);
            node.InnerText = title;

            field = doc.CreateElement("p:Field2", "http://www.xxxx.com/myform/2009");
            node = group.AppendChild(field);
            node.InnerText = status;

            field = doc.CreateElement("p:Field3", "http://www.xxxx.com/myform/2009");
            node = group.AppendChild(field);
            node.InnerText = mydate.ToString();

          MainDataSource.CreateNavigator().SelectSingleNode("/p:myrootElement/p:Items", NamespaceManager).AppendChild(doc.DocumentElement.CreateNavigator());


        private void DeleteFirstEmptyItem()


        XPathNavigator domNav = MainDataSource.CreateNavigator();

        XPathNavigator itemNav = domNav.SelectSingleNode("/p:myrootElement/p:Items/p:Item[1]", NamespaceManager);

        if (itemNav != null)




Thanks in advance,

martix February 17th, 2014 04:50 AM

Thanks for sharing information's....

All times are GMT -4. The time now is 05:45 PM.

Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
2013 John Wiley & Sons, Inc.