Showing posts with label Retrieving list data in SilverLight. Show all posts
Showing posts with label Retrieving list data in SilverLight. Show all posts

Friday, 11 July 2014

Retrieving list data in SilverLight

Retrieving list data in SilverLight
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 Microsoft.SDK.SharePointServices.Samples
{
public partial class MainPage : UserControl
{
Web oWebsite;
ListCollection collList;
IEnumerable listInfo;
public MainPage()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
ClientContext clientContext = ClientContext.Current;
oWebsite = clientContext.Web;
ListCollection collList = oWebsite.Lists;
clientContext.Load(oWebsite,
website=>website.Title);
listInfo = clientContext.LoadQuery(
collList.Include(
list=>list.Title,
list=>list.Fields.Include(
field=>field.Title).Where(
field=>field.Required == true
&& field.Hidden != true)));
clientContext.ExecuteQueryAsync(onQuerySucceeded, onQueryFailed);
}
private void onQuerySucceeded(object sender, ClientRequestSucceededEventArgs args)
{
UpdateUIMethod updateUI = DisplayInfo;
this.Dispatcher.BeginInvoke(updateUI);
}
private void onQueryFailed(object sender, ClientRequestFailedEventArgs args)
{
MessageBox.Show = "Request failed. " + args.Message + "\n" + args.StackTrace;
}
private void DisplayInfo()
{
MyOutput.Text = "Title: " + oWebsite.Title;
collList = oWebsite.Lists;
foreach (List oList in listInfo)
{
MyOutput.Text += "\n\tList: " + oList.Title;
FieldCollection collField = oList.Fields;
foreach (Field oField in collField)
{
MyOutput.Text += "\n\t\tField: " + oField.Title;
}
}
}
private delegate void UpdateUIMethod();
}
}