Get list items with Silverlight in Sharepoint 2010
In SharePoint 2010 we use three types of Client Object model extenstions. To get all items using .Net managed client Object model see -
.Net managed client Object model -
To get all items using ECMASCRIPT\Javascript object model see -
Using ECMAScript
In this post however, we will see an example of retrieving list items using Silverlight Client object model in SharePoint 2010.
using SP = Microsoft.SharePoint.Client;
namespace SPSilverlight
{
public partial class MainPage : UserControl
{
IEnumerable < SP.List > listItems = null;
public MainPage()
{
InitializeComponent();
}
private void getItemsSucceeded(object sender,
Microsoft.SharePoint.Client.ClientRequestSucceededEventArgs e)
{
Dispatcher.BeginInvoke(() = >
{
listBox1.ItemsSource = listItems;
listBox1.DisplayMemberPath = "Title";
});
}
private void getItemsRequestFailed(object sender,
Microsoft.SharePoint.Client.ClientRequestFailedEventArgs e)
{
Dispatcher.BeginInvoke(() = >
{
MessageBox.Show("Error: " + e.ErrorCode + " " + e.ErrorDetails + "
" + e.Message + " " + e.StackTrace.ToString());
});
}
private void button1_Click(object sender, RoutedEventArgs e)
{
ClientContext context = null;
if (App.Current.IsRunningOutOfBrowser)
{
context = new ClientContext(
"http://SP2010Site");
}
else
{
context = ClientContext.Current;
}
var query = from listCollection
in context.Web.Lists
where listCollection.Title != null
select listCollection;
listItems = context.LoadQuery(query);
ClientRequestSucceededEventHandler success = new
ClientRequestSucceededEventHandler(getItemsSucceeded);
ClientRequestFailedEventHandler failure = new
ClientRequestFailedEventHandler(getItemsRequestFailed);
context.ExecuteQueryAsync(success, failure);
}
}
}
.Net managed client Object model -
To get all items using ECMASCRIPT\Javascript object model see -
Using ECMAScript
In this post however, we will see an example of retrieving list items using Silverlight Client object model in SharePoint 2010.
using SP = Microsoft.SharePoint.Client;
namespace SPSilverlight
{
public partial class MainPage : UserControl
{
IEnumerable < SP.List > listItems = null;
public MainPage()
{
InitializeComponent();
}
private void getItemsSucceeded(object sender,
Microsoft.SharePoint.Client.ClientRequestSucceededEventArgs e)
{
Dispatcher.BeginInvoke(() = >
{
listBox1.ItemsSource = listItems;
listBox1.DisplayMemberPath = "Title";
});
}
private void getItemsRequestFailed(object sender,
Microsoft.SharePoint.Client.ClientRequestFailedEventArgs e)
{
Dispatcher.BeginInvoke(() = >
{
MessageBox.Show("Error: " + e.ErrorCode + " " + e.ErrorDetails + "
" + e.Message + " " + e.StackTrace.ToString());
});
}
private void button1_Click(object sender, RoutedEventArgs e)
{
ClientContext context = null;
if (App.Current.IsRunningOutOfBrowser)
{
context = new ClientContext(
"http://SP2010Site");
}
else
{
context = ClientContext.Current;
}
var query = from listCollection
in context.Web.Lists
where listCollection.Title != null
select listCollection;
listItems = context.LoadQuery(query);
ClientRequestSucceededEventHandler success = new
ClientRequestSucceededEventHandler(getItemsSucceeded);
ClientRequestFailedEventHandler failure = new
ClientRequestFailedEventHandler(getItemsRequestFailed);
context.ExecuteQueryAsync(success, failure);
}
}
}
0 comments:
Post a Comment