John Liu .NET

View Original

SharePoint ClientContext.List is missing?

The SharePoint Object Model has:

  • SPContext Members
  • SPContext.Current (static)
  • SPContext.Site
  • SPContext.Web
  • SPContext.List

By comparison, the SharePoint Client Object Model only has:

  • ClientContext Members
  • ClientContext.Current (static)
  • ClientContext.Site
  • ClientContext.Web
  • ClientContext.List (AWOL missing!)

Here's one trick I've started using - the current list exists on the page in javascript (ctx.listName)

So using Silverlight's Javascript bridge I'm able to test and pull that value back into Silverlight - without any looping through the ClientContext.Web.Lists.

string listName = string.Format("{0}", HtmlPage.Window.Eval("ctx.listName"));
// using string.Format to take care of null problems
// the ctx.listName looks like a guid

List list = _clientContext.Web.Lists.GetById(new Guid(listName));

 

So taking a step back, this would be the first time I wrote something that uses both client object model at once!