SharePoint Fanatic

SharePoint insights, real world experience

Using the SP2010 Client Object Model in InfoPath managed code

Someone asked me today about using the SharePoint 2010 Client Object Model in Managed Code.  I’ve done this in VSTA (Visual Studio for Tools and Applications) in C#.  It took a bit of experimentation to get it going, here’s how I did it:

I extracted the Client Object Model runtime DLLs from the SharePoint server.  That’s both Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.runtime.dll.  For good measure I also took Microsoft.SharePoint.Client.Runtime.dll.deploy

In my C# (I was using VSTA) as for Managed C# in InfoPath, I:

  1. Added three project references:
    1. System.Core
    2. SharePoint.Client
    3. SharePoint.Client.Runtime
  2. Added Using for SharePoint.Client

 Opened AssemblyInfo.cs to deal with partial trust exception, and added:

using System.Security; //Added to try to resolve the partial trust error: JP
[assembly: AllowPartiallyTrustedCallers]   //Added to try to resolve the partial trust error: JP

 I had to turn the form  from “Automatically determine security level” to “Full Trust”.  This is an InfoPath specific setting, that may affect how this runs as a Farm Solution, and whether it needs a Farm Administrators approval.

 At that point, you can use the Client Object Model.  Getting data is done two different ways:

-          CAML: my native old-style preferred approach for simple queries

-          LINQ: for SQL-like queries; the one catch is you need to use SPMetal to create a runtime Thunk of sorts specific to your target sites/lists

Hope that helps!

About these ads

2 Responses to Using the SP2010 Client Object Model in InfoPath managed code

  1. Vivek March 14, 2013 at 6:27 am

    Hey
    I am using cOM in to InfoPath since long time, and now would like to use Linq as well in InfoPath using COM, but getting Syntax error and some how VSTA is not able to take reference of Linq objects in code. I could add Microsoft.SharePoint.Linq, but still its not allowing to use Linq objects.
    So have you ever tried practically ?

    Please share . Thanks

    • Joel Plaut March 14, 2013 at 6:36 am

      Vivek:

      What version of InfoPath are you using?

      For your references, be sure to use “System.Xml.Linq” and not the “System.Linq”. Let me know if this does the trick.

      Have you compiled the site using SPMetal to generate the entity model references? that’s needed for some uses.

      VSTA is not quite VS2010. Although for InfoPath work I find VSTA to be totally fine.

      Warm regards,

      Joel

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 )

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

Follow

Get every new post delivered to your Inbox.

Join 64 other followers

%d bloggers like this: