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!
}
}
}
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!
}
}
}
Thanks for the post about SharePoint. it's one of the best platform site in microsoft. it's free developing. Sharepoint Development
ReplyDeletethank you MJ
ReplyDelete