Query an InfoPath form using Linq to XML

An InfoPath form is, at its heart, simply an xml document. As such, you can use Linq To XML to query it (or make changes, etc). There is one small trick to it though. You must include the “my” namespace that InfoPath generates in its forms. check out this example:

XNamespace myNamespace = "http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-02-15T09:18:32";
// then incorporate the namespace into your normal query
var people = from groupnode in xdoc.Root.Descendants(myNamespace + "groupnode")

Once you do that, your gold!

Now, if anyone can tell me how to use LINQ to XML in the code behind of an InfoPath form, I’d be really grateful!



About lelandholmquest

After serving in the Navy as a Reactor Operator on fast attack submarines, I earned both a Bachelor's and Masters in Information Technology from American InterContinental University and am currently working on my doctorate. I have a beautiful wife and two of the sweetest daughters a man could ask for. And I work for the greatest company: Microsoft. At Microsoft I work on the knowledge management system for Microsoft Services: Campus on Office 365.
This entry was posted in C# Programming. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s