Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Other Office > Infopath
|
Infopath Programming and automation discussions only please. :)
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Infopath section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 7th, 2011, 06:27 PM
Authorized User
 
Join Date: Jan 2010
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default SharePoint as secondary data source

Hi,

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.SelectSingleNod e("@Field1", NamespaceManager));

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

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

// Increment the counter

counter++;

// Add the item to the repeating table

AddItem(title, status, myDate);

}


// Remove the first empty item from the repeating table

DeleteFirstEmptyItem();
}



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();
doc.AppendChild(group);

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)

itemNav.DeleteSelf();

}










}




}


Thanks in advance,





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to handle NULL's in the first row of a SharePoint list using an XML data source? aaqqqa BOOK: Professional SQL Server 2005 Reporting Services ISBN: 0-7645-8497-9 0 January 20th, 2011 10:26 AM
Two data table adapter not created when using data source wizard in VS 2008 sakshismriti Visual Studio 2008 0 November 17th, 2010 01:33 AM
CreateUserWizard secondary table Return_Value jonnyO ADO.NET 0 November 16th, 2006 01:41 AM
Secondary Data Source for Word Template Loralee Access 2 May 9th, 2006 07:48 PM
How To Populate ListBox from a Secondary Data Sour luca ASP.NET 1.0 and 1.1 Basics 4 December 1st, 2004 05:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.