LINQ with InfoPath in VSTA - InfoPath Dev
in

InfoPath Dev

LINQ with InfoPath in VSTA

Last post 01-19-2011 09:18 AM by barberj. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 05-23-2009 05:35 AM

    • dga63
    • Not Ranked
    • Joined on 05-23-2009
    • Posts 2

    LINQ with InfoPath in VSTA

    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

    Filed under: ,
  • 05-27-2009 11:26 PM In reply to

    Re: LINQ with InfoPath in VSTA

    Hi DGA,

     

    What version are you using? Perhaps you have an old version.  For instance, I do not see syntax highlighting on the var and from keywords - maybe that's because you have an older version of LINQ. On the other hand, maybe you just cut and pasted from something other than VS. 

     
    Patrick Halstead
    Project Manager at Qdabra
  • 06-02-2009 08:32 PM In reply to

    • dga63
    • Not Ranked
    • Joined on 05-23-2009
    • Posts 2

    Re: LINQ with InfoPath in VSTA

    Hi Patrick,

    To be clear, this is not a full Visual Studio ... it's "Microsoft Visual Studio Tools for Applications" (VSTA), which is a built-in extension capability in InfoPath 2007 (and other Office 2007 products, and is available to third parties to provide similar extension capability, I think).  Poking about a bit it looks like the VSTA that comes with InfoPath might be VS2005-based, and that may be the source of the problem ... not clear if VS2005 has the necessary LINQ awareness.

    I have since migrated the project from VSTA (essentially built-in to InfoPath) into a demo version of VS 2008 Pro, and everything works fine once I do that.  As this is something of a hobby effort, I was hoping to do all this without needing to buy VS ... but I am enjoying the development better in VS and so I might just have to give in and accept that hobbies can be expensive.

    Thanks,

    DGA

  • 01-19-2011 08:50 AM In reply to

    Re: LINQ with InfoPath in VSTA

     I have the same issue even with VS 2008.

    q (the LINQ query) returns as type System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Xml.Linq.XElement,VB$AnonymousType_0`3[System.String,System.String,System.String]]

     Not sure how to get the value out.

    Filed under:
  • 01-19-2011 09:18 AM In reply to

    Re: LINQ with InfoPath in VSTA

     Simple in the end.

    I needed to use item.Descendents instead of item.Element.

    Doh!

Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.