using (ClientContext myContext = new ClientContext(siteurl))
{
/// SAMPlE : 01
myContext.Load(myContext.Site);
myContext.ExecuteQuery();
Console.WriteLine(myContext.Site.Url);
/// SAMPlE : 02
/// Client Object Model Using the Load Method
/*
myContext.Load(myContext.Web, web => web.Lists.Include(list => list.Title).Where(field => field.Hidden == false));
myContext.ExecuteQuery();
foreach (List list in myContext.Web.Lists)
{
Console.WriteLine(list.Title);
}
*/
/// SAMPlE : 03
/// Client Object Model Using the LoadQuery Method
/*var query1 = from list1 in myContext.Web.Lists
select list1;*/
var query = from list in myContext.Web.Lists
where list.Hidden == false
select list;
var lists = myContext.LoadQuery(query);
myContext.ExecuteQuery();
foreach (var list in lists)
{
Console.WriteLine(list.Title);
}
Console.Read();
}
Get All List Names and the Corresponding Views Information
using (ClientContext myContext = new ClientContext(siteurl))
{
ClientObjectPrototype
- listProtoype = myContext.Web.Lists.RetrieveItems();
ClientObjectCollectionPrototype viewProtoType =
listProtoype.RetrieveCollectionObject(ListObjectPropertyNames.Views);
viewProtoType.RetrieveItems().Retrieve();
listProtoype.Retrieve();
myContext.ExecuteQuery();
foreach (var list in myContext.Web.Lists )
{
Console.WriteLine("The views in list: " + list.Title);
foreach (View view in list.Views)
{
Console.WriteLine("\t"+view.Title);
}
}
Console.Read();
}
Update Web title using client object model
using (ClientContext myContext = new ClientContext(siteurl))
{
myContext.Load(myContext.Web);
myContext.ExecuteQuery();
myContext.Web.Title = "SP2010 Development Demo Portal";
myContext.Web.Update();
myContext.ExecuteQuery();
}
}
// Add a new list into the SharePoint site.
List newlyAddedList = myContext.Web.Lists.Add(
new ListCreationInformation()
{
Title = "A New List",
Description = "Some Description",
TemplateType = (int) ListTemplateType.Announcements
}
);
newlyAddedList.Update();
myContext.ExecuteQuery();
Comments
Post a Comment