Archive | March 2011

Client Object Model

Overview :
One of the most promising feature of Sharepoint 2010 is Client object model . Though it still supports object model on server side , client side will play an important role in sharepoint development in coming days .

In 2007 we would either go for server object model to execute code within server where sharepoint is hosted or web services from remote desktops to get rid of a license . However there has been performance issue consuming web services . Hence microsoft came up with a new concept called “Client Object model” where we can consume sharepoint object within remote servers .

Why to use Client Object model ?
Fewer web service calls improves performance.
It can be called from ,NET Code, javascript(ECMAScript) or silverlight.
Reduces network congestion, as there is fewer round trips b/w client and servers.
Gets rid of licensing issues.

How it works :
When we call API’s from the client side / silverlight applications, these API’s are bundled in to XML by the object model and sent as a request to server for processing . The server after processing sends backs the response[result] as a JSON object , the object model picks up this and converts it to .NET object exposing it to the user. It can be seen that there is a fewer round trips as the entire operation is bundled and executed at once.

Namespaces :
Microsoft.SharePoint.Client and Microsoft.SharePoint.Client.Runtime are two prominent namespaces used for consuming object model on the client side using C#.

How to use :
All objects now in client model doesn’t begin with SP , i.e : it is Web for SPWeb, List for SPList .The SP concept has been removed in this model. However there are couple of methods that has to be used .
The object whose properties will be accessed in the code has to be first loaded and executed so that they will be ready to access , we will be getting NotInitializedException otherwise.

Load(object whose value properties will be accessed)
ExecuteQuery()

Implmentation ?
using sp = Microsoft.SharePoint.Client;

using (sp.ClientContext objContext = new sp.ClientContext(“url“))
{
sp.Web web = objContext.Web;

//Load and execute List to access its properties
objContext.Load(web.Lists);
objContext.ExecuteQuery();
foreach (sp.List oList in web.Lists)
{
//do something to access OList properties

}

Hope you will be now able to build the application on you own .

Sandbox solution and farm level solution

Sharepoint 2010 has introduced a new concept called sandbox . Solutions can be built on this format so that they reside at site collection level independent of sharepoint farm.
On the other side you can also build soutions at farm level , as it used to be in 2007. Lets now see the differences in these approaches .

Sandbox :It is a place where we can deploy our solution i .e : Site Collection.Solutions in sandbox will have partial trust level with restrictions for accessing resources on servers, database,calling unmanaged code.It can be monitored,managed by site collection administrator.Since it is indepenedent of farm, the solutions will not have any impact at the farm level.

Farm level :Solutions are deployed at the farm level.Solutions execute with full trust. Unlike sandbox these solutions doesn’t have any resrictions.Farm level admin can manage these solutions .