Get a SharePoint List of Client Object Model in SharePoint 2010

One serious benefits provides us with the code in SP2010 is the  Client Object Model
Client Object Model gives us the client-side API.
Example:
Opens a console project


We will Add Reference the DLL to the following: Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll form 14Hive\Isapi folder.


Now type the following code:

using System;
using
System.Linq;
using
MyClientOM = Microsoft.SharePoint.Client;
namespace
TestClientOM
{
    class Program
   
{
       
static void Main(string[] args)
        {
           
string myUrl = "http://mysite.com/";
           
using (MyClientOM.ClientContext ctx = new MyClientOM.ClientContext(myUrl))
           
{
                MyClientOM.Web site = ctx.Web;


                ctx.Load(site);
                ctx.Load(site.Lists);
                ctx.Load(site, x => x.Lists.Where(l => l.Title != null));
                ctx.ExecuteQuery();
                Console.WriteLine("Lists:");
               
foreach (MyClientOM.List list in site.Lists)
                {

                    Console.WriteLine(list.Title);
                }
                Console.ReadKey();
            }
       
}
   
}
}

The code gave us remote access to the site myUrl through code. The code Brought us all the lists on the site.



Thanks
Roi

Comments

Popular posts from this blog

A sharepoint list view of the current month

The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters

Export SharePoint 2010 List to Excel with PowerShell