sharepoint current user can be accessed in silverlight client object model by loading the current user variable to the client context
I have given an example to display the current user name in a textblock.
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;
namespace User
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
cc = new ClientContext(ApplicationContext.Current.Url);
cc.Load(cc.Web,s=>s.CurrentUser); //This is where u load the current use.
cc.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(sucess),null);
}
private void sucess(Object sender, ClientRequestSucceededEventArgs e)
{
Dispatcher.BeginInvoke(data);
}
private void data()
{
textBlock1.Text = cc.Web.CurrentUser.Title;
}
}
}
I have given an example to display the current user name in a textblock.
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;
namespace User
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
cc = new ClientContext(ApplicationContext.Current.Url);
cc.Load(cc.Web,s=>s.CurrentUser); //This is where u load the current use.
cc.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(sucess),null);
}
private void sucess(Object sender, ClientRequestSucceededEventArgs e)
{
Dispatcher.BeginInvoke(data);
}
private void data()
{
textBlock1.Text = cc.Web.CurrentUser.Title;
}
}
}
No comments:
Post a Comment