Its easy to get currently loggedin user name in clientObject Model. below is the code used in silverlight application.
private string GetLoggedUserName()
{
string name = string.Empty;
try
{
ClientContext cnt = new ClientContext("serverUrl");
if (cnt != null)
{
user = cnt.Site.RootWeb.CurrentUser;
cnt.Load(user);
cnt.ExecuteQueryAsync(loginNameSuccess, loginNameFailure);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + " Inner Exception:" + ex.InnerException.Message);
}
return name;
}
private void loginNameSuccess(object sender, ClientRequestSucceededEventArgs e)
{
this.Dispatcher.BeginInvoke(delegate()
{
MessageBox.Show(user.LoginName);
});
}
No comments:
Post a Comment