Q:

Getting DefaultView through client object model

I want to load fields of the default view for Sharepoint list through client object model (I am using Silverlight). Here are some relevant things I've found (on msdn here):

class List has property DefaultViewUrl [of type string]
class List has method GetView(Guid)
class List has property Views [of type ViewCollection]
class ViewCollection has method GetById(Guid)
class ViewCollection has method GetByTitle(string)
class View has property DefaultView [of type bool]

That's everything I was able to find. As you can see there is no direct way of getting DefaultView (there is missing DefaultViewId property on List or GetByUrl(string) method on ViewCollection).
Seems to me as the only solution is to iterate through List.Views collection and check DefaultView property on each View. Which is kind of...well, inefficient...
Did I miss something? Anyone see some straigh solition?
Thanks for ideas.

A:

Try LoadQuery using a LINQ statement
For Example:
private IEnumerable<View> viewQuery = null;
public void LoadDefaultView()
{
    using (ClientContext ctx = ClientContext.Current)
    {
        list = ctx.Web.Lists.GetByTitle("YourList");

        viewQuery = ctx.LoadQuery(list.Views
                   .Include(v => v.Title) // include more lamda statements here to populate View Properties
                   .Where(v => v.DefaultView == true));

        ctx.ExecuteQueryAsync(LoadDefaultViewSuccess, LoadDefaultViewFailure);
    }
}
private void LoadDefaultViewSuccess(object sender, ClientRequestSucceededEventArgs args)
{
    // should only be one View in views
    View defaultView = viewQuery.FirstOrDefault();

    // use default.Title here
}
private void LoadDefaultViewFailure(object sender, ClientRequestFailedEventArgs args)
{
    // handle failure here
}

MSDN SharePoint 2010 Silverlight COM article here
http://msdn.microsoft.com/en-us/library/ee538971.aspx

