Thursday, March 14, 2013

SharePoint Client Object Model (COM) in InfoPath Form

User SharePoint Foundation 2010 Managed Client Object Model (COM) in InfoPath Form
  
 
Friends,
 
I am using InfoPath 2010 frequently to fetch SharePoint list items as well as to create new List items or delete/update existing entries using traditional List.asmx web service. But this needs lots of manual work and bored of creating CAML based XML files for any operation. So already I was looking some other alternative.  

And in the same time Microsoft launches SharePoint 2010, in which Microsoft introduced Managed Client Object Model. So I was wondering why can't I use COM in InfoPath to do operations on SharePoint.
 
Finally I could do all operations using COM in InfoPath and life has become very easy :)
 
So please find the steps below...
 
  • Go to VSTA from InfoPath (Code behind of InfoPath form)

  • Add reference below DLL
    • Microsoft.SharePoint.Client
    • Microsoft.SharePoint.Client.Runtime

  • Add below Namespace
using Microsoft.SharePoint.Client;
using SP = Microsoft.SharePoint.Client;
 
  • Go to Button event and write below code to Create New Item to SharePoint List


void CreateNewSharePoingListItem()

{

//Initial declaration and initialization
ClientContext ctx = new ClientContext(siteURL.ToString());
SP.List instList = ctx.Web.Lists.GetByTitle("ListName"); 

//Creating List instance and assign values to columns
ListItemCreationInformation masterItemInformation = new ListItemCreationInformation();
ListItem masterItem = instList.AddItem(masterItemInformation);
masterItem["FieldName1"] = "Value1";
masterItem["FieldName2"] = "Value2"; 

//Finally send command to Server for updation
masterItem.Update();
ctx.ExecuteQuery();

}

  • Just execute above code, it will create new item to SharePoint list

The similar way you can do all other CRUD operations using COM via InfoPath. Please go through official Microsoft documentations to use Managed COM here.

You must be wondering what steps require while Publishing this form to server, but luckily no extra steps require to publish or register the above DLL separately, the InfoPath will manage automatically :)

Hope this will save your Coding time and you can go home EARLY to do something else better :) :)  
 

Thursday, June 18, 2009

Testing blog

This is my testing ब्लॉग
हेल्लो भई लोग , अपुन ने ब्लॉग लिखने का चालू किए ला है...बोले तो बिंदास कमेन्ट डालो...