Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Other Office > Infopath
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 7th, 2011, 06:27 PM
Authorized User
Points: 134, Level: 2
Points: 134, Level: 2 Points: 134, Level: 2 Points: 134, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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,
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 09:26 AM
Two data table adapter not created when using data source wizard in VS 2008 sakshismriti Visual Studio 2008 0 November 17th, 2010 12:33 AM
CreateUserWizard secondary table Return_Value jonnyO ADO.NET 0 November 16th, 2006 12: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 04:24 PM



All times are GMT -4. The time now is 12:23 AM.


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