Microsoft Premier Field Engineer - SharePoint

All posts are provided "AS IS" with no warranties, and confers no rights.

Silverlight Object Model code to access the current user of a SP2010 site

Silverlight Object Model code to access the current user of a SP2010 site

  • Comments 1

More details on the Silverlight Object Model, you can find here.

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 Microsoft.SharePoint.Client;
using Microsoft.SharePoint;

namespace SilverlightApplication1
{
    public partial class MainPage : UserControl
    {
        Web oWebsite;
        ListCollection collList;
        IEnumerable<List> listInfo;
        User user;

        public MainPage()
        {
            InitializeComponent();
            SilverlightOM();
        }

         public void SilverlightOM()
        {
            ClientContext clientContext = new ClientContext("http://fly2010");

            oWebsite = clientContext.Web;
            collList = oWebsite.Lists;

            clientContext.Load(oWebsite, s => s.CurrentUser);
            clientContext.ExecuteQueryAsync(onQuerySucceeded, onQueryFailed);
        }

        private void onQuerySucceeded(object sender, ClientRequestSucceededEventArgs args)
        {
             user = oWebsite.CurrentUser;
        }

        private void onQueryFailed(object sender, ClientRequestFailedEventArgs args)
        {
            MessageBox.Show("Request failed");
        }
    }
}
Comments
  • Great! Now how do you get their groups to show/hide content within the XAP?  Or does most people create multiple silverlight applications, one for each group?  Thanks.

Page 1 of 1 (1 items)
Leave a Comment
  • Please add 8 and 4 and type the answer here:
  • Post