Thursday, June 3, 2010

Get loginname of the Sharepoint user with username efficently

Share/Save/Bookmark

If you wonder how to get login name with user name programmatically in SharePoint then you are reading the right post.
We can do this by looping all the users of web and get the spuser that matches with the username or by simply using SPFieldUserValue like below,
using (SPSite site = new SPSite("http://sharepointcustomization.blogspot.com/"))
{
using (SPWeb web = site.OpenWeb())
{
SPFieldUserValue userValue = new SPFieldUserValue(web, "UserName");
if (userValue.User.LoginName == web.CurrentUser.LoginName)
{
//do something!
}
}
}

Subscribe

2 comments:

  1. Thanks for the post about SharePoint. it's one of the best platform site in microsoft. it's free developing. Sharepoint Development

    ReplyDelete