Reputation: 4878
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):
List
has property DefaultViewUrl
[of type string
]List
has method GetView(Guid)
List
has property Views
[of type ViewCollection
]ViewCollection
has method GetById(Guid)
ViewCollection
has method GetByTitle(string)
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.
Upvotes: 0
Views: 4848
Reputation: 26
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
Upvotes: 1
Reputation: 27415
What about SPList.DefaultView
? The SPList DefaultView member is an SPView object (not bool)
Upvotes: 0