SharePoint2010 Sliverlight Client OM
SharePoint2010 Sliverlight List Web Part Using Client Object Model.
Please read more about my earlier post related to name as “ SharePoint2010
Client Model With Example” describe the different-2 ways of fetching the
data using SharePoint 2010 Client OM.
Open Visual Studio 2010 Create a new project under
SliverLight project category. Give it name let say ex “SilverLightListWebPart”
Paste the following code in MainPage.xaml
<UserControl x:Class="SilverLightListWebPart.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<ListBox Name="listbox1" Width="200" Height="400"
HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top"/>
</Grid>
</UserControl>
MainPage.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.SharePoint.Client;
namespace SilverLightListWebPart
{
public partial
class MainPage
: UserControl
{
IEnumerable<List> _genericList;
public
MainPage()
{
InitializeComponent();
var
ctx = ClientContext.Current;
_genericList =
ctx.LoadQuery(ctx.Web.Lists.Include
(l => l.Title).Where(l =>
l.BaseType == BaseType.GenericList));
ctx.ExecuteQueryAsync(Pass, fail);
}
// in case of
Request pass
public void Pass(object
sender, ClientRequestSucceededEventArgs
args)
{
// Thread
BEGIN
Dispatcher.BeginInvoke(Bindlist);
}
// in case of
Request fail
public void fail(object
sender, ClientRequestFailedEventArgs args)
{
}
public void Bindlist()
{
listbox1.Items.Clear();
listbox1.ItemsSource =
_genericList;
listbox1.DisplayMemberPath = "Title";
}
}
}
Comments
Post a Comment