How to get current User's Manager Name and Manager Email in a visual webpart

Hi,

I am new to programming, I have a requirement to get current userInfo and Manager's info on to a visual webpart.

I am using

  protected void Page_Load(object sender, EventArgs e)
        {
            SPUser user = SPContext.Current.Web.CurrentUser;
            txt1.Text = user.Name;
            txt2.Text = user.LoginName;
            txt3.Text = user.Email;
         }

to get current user info and it works, can anyone help me or send a link to get current User's Manager's Info, any help will be appreciated.

June 23rd, 2015 3:34pm

Hi,

Please use the below code to identify the manager name from the user profile

  +++++++++++++++++++++++++++++++++

   SPSite _site = SPContext.Current.Site;
  
ServerContext serverContext = ServerContext.GetContext(_site);
  
UserProfileManager myUserProfile = new UserProfileManager(serverContext);
  
UserProfile currentUserProfile = myUserProfile .GetUserProfile(System.Web.HttpContext.Current.User.Identity.Name);

  
string departmentName = (string)currentUserProfile["department"].Value;
  
string managerName = (string)currentUserProfile["manager"].Value;
   _site
.RootWeb.Dispose();
   _site
.Dispose();

  +++++++++++++++++++++++++++++++++

Free Windows Admin Tool Kit Click here and download it now
June 23rd, 2015 3:46pm

Hi,

This is a code demo for getting current user's manager:

http://bshouman.blogspot.com/2008/04/get-currently-logged-in-manager.html

Best Regards,

Vincent Han

June 24th, 2015 2:56am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics