arithforu

CSOM

Oct 2nd, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Documents;
  8. using System.Windows.Input;
  9. using System.Windows.Media;
  10. using System.Windows.Media.Animation;
  11. using System.Windows.Shapes;
  12. using ClientOM = Microsoft.SharePoint.Client;
  13. using Microsoft.SharePoint.Client;
  14.  
  15. namespace SLCSTest
  16. {
  17.     public partial class MainPage : UserControl
  18.     {
  19.         Web oWebsite;
  20.         ListCollection collList;
  21.         IEnumerable<List> listInfo;
  22.  
  23.         public MainPage()
  24.         {
  25.             InitializeComponent();
  26.         }
  27.  
  28.         private void Button_Click(object sender, RoutedEventArgs e)
  29.         {
  30.             ClientContext clientContext = ClientContext.Current;
  31.             oWebsite = clientContext.Web;
  32.             ListCollection collList = oWebsite.Lists;
  33.  
  34.             clientContext.Load(oWebsite,
  35.                website => website.Title);
  36.  
  37.             listInfo = clientContext.LoadQuery(
  38.                collList.Include(
  39.                    list => list.Title,
  40.                    list => list.Fields.Include(
  41.                        field => field.Title).Where(
  42.                        field => field.Required == true
  43.                        && field.Hidden != true)));
  44.  
  45.             clientContext.ExecuteQueryAsync(onQuerySucceeded, onQueryFailed);
  46.         }
  47.  
  48.         private void onQuerySucceeded(object sender, ClientRequestSucceededEventArgs args)
  49.         {
  50.             UpdateUIMethod updateUI = DisplayInfo;
  51.             this.Dispatcher.BeginInvoke(updateUI);
  52.         }
  53.  
  54.         private void onQueryFailed(object sender, ClientRequestFailedEventArgs args)
  55.         {
  56.             btnButton.Content  = "Request failed. " + args.Message + "\n" + args.StackTrace;
  57.         }
  58.  
  59.         private void DisplayInfo()
  60.         {
  61.             btnButton.Content = "Title: " + oWebsite.Title;
  62.             collList = oWebsite.Lists;
  63.  
  64.             foreach (List oList in listInfo)
  65.             {
  66.                 btnButton.Content += "\n\tList: " + oList.Title;
  67.  
  68.                 FieldCollection collField = oList.Fields;
  69.                 foreach (Field oField in collField)
  70.                 {
  71.                     btnButton.Content += "\n\t\tField: " + oField.Title;
  72.                 }
  73.             }
  74.         }
  75.  
  76.         private delegate void UpdateUIMethod();
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment