I'm trying to use LINQ in InfoPath FormCode, using VSTA as provided with InfoPath 2007. The issue I am experiencing is that VSTA does not permit the LINQ query syntax.
For instance, there are code samples posted at http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2009/04/29/code-samples-from-my-short-talk-about-linq-to-xml.aspx. This part of that code works fine:
XDocument infoPathDocument = XDocument.Load(new System.IO.StringReader(MainDataSource.CreateNavigator().OuterXml));
However, the query does not:
var items = from item in infoPathDocument.Descendants(myNamespace + "Item")
select new
{
Name = item.Element(myNamespace + "Name").Value,
...
};
In the VSTA editor, it starts complaining at the "item" following "= from", and so the build fails.
Some details that folks might ask about:
1. I am doing ...
using Microsoft.Office.InfoPath;
using System;
using System.Linq;
using System.Xml.Linq;
using System.Xml;
using System.Xml.XPath;
2. I have manually added References to System.Core and System.Xml.Linq to support the above.
I would greatly appreciate suggestions about what I might be missing, in getting this to work ...
Thanks in advance !
DGA