locked
Get The Login UserName and ID RRS feed

  • Question

  • Hi,

      I am working with Visual Studio 2008 and developing Visual WebPart so I have to get the Login Perosn EmpId and Name .

    So please provide me the code so that i could get the Current login Employee Detaisl?

     

     

    Thursday, March 24, 2011 12:27 PM

Answers

  • Hi,

    Just use below code sample to get current user info.

    public string GetCurrentuserName()
            {          
                        SPUser objspuser = ObjWeb.CurrentUser;
                        string strCurrentuser = objspuser.Name;  ////Here you can get ID and other info's
    
                        if (strCurrentuser.Contains("\\"))
                        {
                            strCurrentuser = objspuser.Name.ToString().Split('\\')[1].ToString();
                        }
                        else
                        {
                            strCurrentuser = objspuser.Name.ToString();
                        }
                        return strCurrentuser;
                    }

    Hope it could help


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"

    Thursday, March 24, 2011 12:36 PM
  • Hi

    Just use this code:

    SPUser currentUser = SPContext.Current.Web.CurrentUser;

    currentUser object has all required properties you need.


    to Hemendra: Sorry, why you are opening the site/web?

     

     

    ___________________________________

    Zorayr Zakaryan Lightning Tools

    • Proposed as answer by Ghouse Friday, March 25, 2011 7:06 AM
    • Marked as answer by Leoyi Sun Friday, April 1, 2011 2:22 AM
    Thursday, March 24, 2011 3:38 PM

All replies

  • Hi,

    Just use below code sample to get current user info.

    public string GetCurrentuserName()
            {          
                        SPUser objspuser = ObjWeb.CurrentUser;
                        string strCurrentuser = objspuser.Name;  ////Here you can get ID and other info's
    
                        if (strCurrentuser.Contains("\\"))
                        {
                            strCurrentuser = objspuser.Name.ToString().Split('\\')[1].ToString();
                        }
                        else
                        {
                            strCurrentuser = objspuser.Name.ToString();
                        }
                        return strCurrentuser;
                    }

    Hope it could help


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"

    Thursday, March 24, 2011 12:36 PM
  • Hi

    Just use this code:

    SPUser currentUser = SPContext.Current.Web.CurrentUser;

    currentUser object has all required properties you need.


    to Hemendra: Sorry, why you are opening the site/web?

     

     

    ___________________________________

    Zorayr Zakaryan Lightning Tools

    • Proposed as answer by Ghouse Friday, March 25, 2011 7:06 AM
    • Marked as answer by Leoyi Sun Friday, April 1, 2011 2:22 AM
    Thursday, March 24, 2011 3:38 PM