Well Some time back, I got a request from the Client to use the data from SharePoint into Win Form application, well in order to do so i used already exposed WebService in order to interact with the SharePoint. But in one of the requirement i wrote some additional WebService.
So, Microsoft SharePoint Team takes the SharePoint to the next level, providing a managed code Client side object model to execute the request just as to execute code on the Server.
SharePoint 2010 provides the two assemblies, Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll.
These assemblies provides the functionality from creating a site to update a List Item in the List.
Considering that Client Side application will contribute into the Network traffic when corresponding to the Server. So rather than making a call to Server on each Step, the request can be bundle up and send in one go, so that it ease out the Network Traffic.
As it can been from the above diagram, a xml request send to the server and server send JSON in response, it is totally upto you when you want to make a call to server and get the response
The Client side object model extends the same legacy for creating a Context from the Server Object Model. Hence you can retrieve the site reference from the this Context.
For demo, i have created Winform Applicaiton which shows the all the List and its Item in the given site.
As it can be noticed from the below application i have placed a TextBox for submitting Site URL, a button to retrieve the List collection into the ListBox Control and DataGridView to display the Item Field Title
Open Visual Studio 2010,
Create a Winform Application,
First Copy and paste Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll from %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\ISAPI to some common location like in bin directory of the project. than Add these dlls as reference.
above is the code for button click to submit the Site URL, as it can be noticed that it correspond to the Server, only when it execute the ClientContext.ExecuteQuery();
ClientContext.Load() only register the objects, it is up to the Solution architect to decide how often to execute the ExecuteQuery Method. Another interesting aspect to notice that when providing the Site URL to context, the Client Object Model wont call the server, rather than wait for Execute Query method to run.
thanks for reading,
your comments and feedback is required,
Happy SharePointing 🙂