Partager via


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

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("https://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

  • Anonymous
    December 03, 2010
    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.