{"id":2189,"date":"2011-12-27T09:25:24","date_gmt":"2011-12-27T09:25:24","guid":{"rendered":"https:\/\/poiseddevelopers.com\/reality-tech\/?p=2189"},"modified":"2024-05-06T12:16:42","modified_gmt":"2024-05-06T12:16:42","slug":"using-the-sp2013-client-object-model-in-infopath-managed-code","status":"publish","type":"post","link":"https:\/\/poiseddevelopers.com\/reality-tech\/using-the-sp2010-client-object-model-in-infopath-managed-code\/","title":{"rendered":"Using the SP2013 Client Object Model in InfoPath managed code"},"content":{"rendered":"<p>Someone asked me today about using the SharePoint 2013 Client Object Model in Managed Code.\u00a0 I\u2019ve done this in VSTA (Visual Studio for Tools and Applications) in C#.\u00a0 It took a bit of experimentation to get it going, here\u2019s how I did it:<\/p>\n<p>I extracted the Client Object Model runtime DLLs from the SharePoint server.\u00a0 That\u2019s both Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.runtime.dll.\u00a0 For good measure I also took Microsoft.SharePoint.Client.Runtime.dll.deploy<\/p>\n<p>In my C# (I was using VSTA) as for Managed C# in InfoPath, I:<\/p>\n<ol>\n<li>Added three project references:\n<ol>\n<li>System.Core<\/li>\n<li>SharePoint.Client<\/li>\n<li>SharePoint.Client.Runtime<\/li>\n<\/ol>\n<\/li>\n<li>Added Using for SharePoint.Client<\/li>\n<\/ol>\n<p>Opened AssemblyInfo.cs to deal with partial trust exception, and added:<\/p>\n<pre lang=\"php\">using System.Security; \/\/Added to try to resolve the partial trust error: JP\r\n[assembly: AllowPartiallyTrustedCallers] \/\/Added to try to resolve the partial trust error: JP<\/pre>\n<p>&nbsp;<\/p>\n<p>At that point, you can use the Client Object Model.\u00a0 Getting data is done two different ways:<\/p>\n<p>\u2013\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 CAML: my native old-style preferred approach for simple queries<\/p>\n<p>\u2013\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 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<\/p>\n<p>Hope that helps!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Someone asked me today about using the SharePoint 2013 Client Object Model in Managed Code.\u00a0 I\u2019ve done this in VSTA (Visual Studio for Tools and Applications) in C#.\u00a0 It took a bit of experimentation to get it going, here\u2019s how I did it: I extracted the Client Object Model runtime DLLs from the SharePoint server.\u00a0 [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":2191,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[28],"tags":[],"class_list":["post-2189","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c"],"acf":[],"_links":{"self":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts\/2189","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/comments?post=2189"}],"version-history":[{"count":3,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts\/2189\/revisions"}],"predecessor-version":[{"id":3024,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts\/2189\/revisions\/3024"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/media\/2191"}],"wp:attachment":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/media?parent=2189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/categories?post=2189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/tags?post=2189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}