Thursday, October 11, 2012

Working with Client object model in SharePoint 2013




Here we will discuss how to work with SharePoint 2013 client object model using Visual Studio 2012. Before reading this you can check some new features in SharePoint 2013.

In this post we will discuss how we can retrieve title of a SharePoint site by using client object model.

To work with client object model we need 2 DLLs.

- Microsoft.SharePoint.Client.Runtime.dll
- Microsoft.SharePoint.Client.dll

The above 2 dlls are located inside 15 hive directory in the below location:
%ProgramFiles%\Common Files\Microsoft Shared\web server extensions\15\ISAPI

But If you are creating an app for SharePoint 2013 using Visual Studio 2012 then the above 2 dlls will be automatically added.

Below is the code to retrive the web title:

using Microsoft.SharePoint.Client;

void GetWebTitle()
{

ClientContext context = new ClientContext("http://[SharePoint Site URL]");

Web web = context.Web;

context.Load(web);

context.ExecuteQuery();

string title = web.Title;

}


0 comments:

Post a Comment

Twitter Delicious Facebook Digg Favorites More