locked
need display user list (with their details ) by filtering their department from active directory RRS feed

  • Question

  • User456628452 posted

    hi, i need display user list (with their details ) by filtering their department from active directory, from the code i have written it only retrieves single user.

    i want to generate user list by filtering their departments. i didnt know how to retrieve all the department list and users listed in the department.

    public ActionResult Index()
            {
                var username = User.Identity.Name;
    
    
                using (var context = new PrincipalContext(ContextType.Domain, "mydomainname"))
                {
                    var user = UserPrincipal.FindByIdentity(context, username);
                    if (user.GetUnderlyingObjectType() == typeof(DirectoryEntry))
                    {
                        using (var entry = (DirectoryEntry)user.GetUnderlyingObject())
                        {
                            if (entry.Properties["DisplayName"] != null)
                                ViewBag.UserName = entry.Properties["DisplayName"].Value.ToString();
    
                            ViewBag.Email = user.EmailAddress;
    
    
                            if (entry.Properties["TelephoneNumber"] != null)
                                ViewBag.InterCom = entry.Properties["TelephoneNumber"].Value.ToString();
    
                            if (entry.Properties["Mobile"] != null)
                                ViewBag.MobileNo = entry.Properties["Mobile"].Value.ToString();
    
    
    
                            if (entry.Properties["Title"] != null)
                                ViewBag.JobTitle = entry.Properties["Title"].Value.ToString();
    
    
    
                            if (entry.Properties["Department"] != null)
                                ViewBag.Department = entry.Properties["Department"].Value.ToString();
    
                            if (entry.Properties["Company"] != null)
                                ViewBag.Company = entry.Properties["Company"].Value.ToString();
                         
                        }
                    }
    
    
                }
    
                return View();
    
            }
    
    

    Monday, November 18, 2019 10:14 AM

Answers