locked
Using LINQ to Sharepoint in InfoPath form's code behind. RRS feed

  • Question

  • Hi,

    I can't find any info on how to use LINQ to sharepoint in an InfoPath form's Code Behind. In one of the blogs (don't remember now) it was stated that since VSTA assemblies are still 32 bits , the Code Behind of an Infopath form can't use LINQ to sharepoint (64 bits).

    Is this the case? if yes, what can be used as an alternative to LINQ to Sharepoint in InfoPath Code Behind. (CAML, Sharepoint Client Object Model...?)

    Thank you.


    Facimus
    Tuesday, March 1, 2011 1:32 PM

Answers

  • LINQ to SharePoint actually converts all of your queries into CAML queries anyway .. (and in some cases executes it as several CAML queries !! so be careful with big or complex queries!).

    I'm not sure about the 64-bit restrictions, but simply because SPMetal with InfoPath isn't a pretty prospect I would recommend using CAML queries or Client Object Model.

    Of course .. depending on what you are trying to query, you might find there is an OOB approach if it is running on SharePoint Forms Services?


    regards
    Martin Hatch
    MCPD SharePoint 2010 | .Net Web Development
    MCTS WSS 3.0 | MOSS 2007
    Visit my Blog - www.martinhatch.com
    • Marked as answer by Facimus Tuesday, March 1, 2011 10:11 PM
    Tuesday, March 1, 2011 2:15 PM
  • Thanks for all the info on deploying the Infopath form template properly. I decided to use CAML query with SPQuery() for querying SP list in the code behind of an Infopath form.
    Facimus
    • Marked as answer by Facimus Tuesday, March 1, 2011 10:13 PM
    Tuesday, March 1, 2011 10:11 PM

All replies

  • LINQ to SharePoint actually converts all of your queries into CAML queries anyway .. (and in some cases executes it as several CAML queries !! so be careful with big or complex queries!).

    I'm not sure about the 64-bit restrictions, but simply because SPMetal with InfoPath isn't a pretty prospect I would recommend using CAML queries or Client Object Model.

    Of course .. depending on what you are trying to query, you might find there is an OOB approach if it is running on SharePoint Forms Services?


    regards
    Martin Hatch
    MCPD SharePoint 2010 | .Net Web Development
    MCTS WSS 3.0 | MOSS 2007
    Visit my Blog - www.martinhatch.com
    • Marked as answer by Facimus Tuesday, March 1, 2011 10:11 PM
    Tuesday, March 1, 2011 2:15 PM
  • Hi Martin,

    Thanks for the reply. I am deploying Infopath brower forms with code behind to a Form Library in sp2010 server. What I need is to query Sharepoint Lists-Libraries in the form code behind simply (No BCD or external data). If OOB solutions present they are wellcome too :).

    Thanks.


    Facimus
    Tuesday, March 1, 2011 2:23 PM
  • You can actually hook directly into the SharePoint API, referencing Microsoft.SharePoint.dll in your code-behind.

    You may find that when you deploy it you get "cannot find Microsoft.SharePoint.dll" which bizarrely worked when I dropped that DLL into the Feature Folder where my XSN was deployed from! (weird)


    regards
    Martin Hatch
    MCPD SharePoint 2010 | .Net Web Development
    MCTS WSS 3.0 | MOSS 2007
    Visit my Blog - www.martinhatch.com
    Tuesday, March 1, 2011 2:32 PM
  • Intersting point :). What you mean by "Feature Folder where my XSN was deployed from" ?

    Thx.


    Facimus
    Tuesday, March 1, 2011 2:39 PM
  • Erm .. I deploy my InfoPath forms using a feature which deploys them to the FormServerTemplates and then registers them for use with Form Services.

    That way I can use standard WSPs to roll them into Dev / Test / UAT / Production ..

    (they also upgrade nicely too)

    Why? How did you do it?


    regards
    Martin Hatch
    MCPD SharePoint 2010 | .Net Web Development
    MCTS WSS 3.0 | MOSS 2007
    Visit my Blog - www.martinhatch.com
    Tuesday, March 1, 2011 2:41 PM
  • I don't have my own code with me (on client site) .. but some references:

    http://skurocks.wordpress.com/2008/09/19/deployment-of-infopath-form-%E2%80%93-the-right-way/

    http://blah.winsmarts.com/2008-8-Deploying_InfoPath_2007_Forms_to_Forms_Server_-and-ndash_Properly.aspx

    (they are not SP2010 .. but theory is the same)

    The key bit is the Receiver Class and Receiver Assembly

    ReceiverClass="Microsoft.Office.InfoPath.Server.Administration.XsnFeatureReceiver"

    ReceiverAssembly="Microsoft.Office.InfoPath.Server, Version=12.0.0.0, Culture=neutral .... etc

    The main thing you need to change is that SharePoint 2010 is Version=14.0.0.0 is


    regards
    Martin Hatch
    MCPD SharePoint 2010 | .Net Web Development
    MCTS WSS 3.0 | MOSS 2007
    Visit my Blog - www.martinhatch.com
    Tuesday, March 1, 2011 2:44 PM
  • ach .. sorry .. the explanation (more speed less haste, eh?)

    What you basically do is include your XSN in a <Module> which deploys your XSN file to Url="FormServerTemplates"

    This will make sure your XSN file (i.e. your InfoPath Form Template) gets properly rolled out to your Site Collection.

    You then make sure your Feature (which is provisioning your Module) includes a Feature receiver reference to the Microsoft.Office.InfoPath.Server.Administration.XsnFeatureReceiver class (as my post above).

    This will (drum roll):

    • Install your XSN into the Form Services bits in Central Adminsitration
    • Register it with Form Services (so it can run in a browser).

    The main kicker is that you need to Publish your InfoPath Form to a Network Location BEFORE you place it in your Visual Studio project.

    After that it should be smooth sailing .. you just add your Content Type to a Forms Library and job done! :D


    regards
    Martin Hatch
    MCPD SharePoint 2010 | .Net Web Development
    MCTS WSS 3.0 | MOSS 2007
    Visit my Blog - www.martinhatch.com
    Tuesday, March 1, 2011 2:48 PM
  • Thanks for all the info on deploying the Infopath form template properly. I decided to use CAML query with SPQuery() for querying SP list in the code behind of an Infopath form.
    Facimus
    • Marked as answer by Facimus Tuesday, March 1, 2011 10:13 PM
    Tuesday, March 1, 2011 10:11 PM