Get current loggedin user using silverlight client object model
How to get sharepoint Current User in Silverlight Client Object Model
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;
}
}
}
To get current user in server object model see this link
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;
}
}
}
To get current user in server object model see this link
Comments
Post a Comment