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:
The code gave us remote access to the site myUrl through code. The code Brought us all the lists on the site.
Thanks
Roi
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
{
using System.Linq;
using MyClientOM = Microsoft.SharePoint.Client;
namespace TestClientOM
{
class Program
{
static void Main(string[] args)
{
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)
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();
}
}
}
}
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
Post a Comment