4

I want to create a Company Directory so that everyone can access to a list/directory of all people in our company. It also should be searchable. I think we need 2 sites for this: 1) Search site, which will be used by all the other sites 2) Company Directory site our company have the info on all people (name, title, contact, photo...) on Active Directory. The task is to get this data and display it in SharePoint 2013 as Company Directory. So, my question are:

  1. Which template should I use for Company Directory site?
  2. Is there any tutorial to implement search for this site?
  3. How can I get data from Active Directory to display it in SP 2013?
  • How is People Search not meeting your needs? – Matthew McDermott Sep 25 '14 at 22:07
2

I have been migrating profiles from AD to SharePoint list and created a directory for internal reference.

1) For connecting and migrating data from Active directory use the below code in a webpart on page load:

    DirectoryEntry entry;
    DirectorySearcher search;
    SearchResultCollection results;
    try{
        SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            using (SPSite siteCollection = new SPSite(SPContext.Current.Site.Url))
            {
                using (SPWeb site = siteCollection.OpenWeb())
                {
                    entry = GetDirectoryEntry();
                    search = new DirectorySearcher(entry);
                    search.Filter = "(&(objectClass=user)(objectCategory=person))";
                    results = search.FindAll();
                    this.Controls.Add(new Literal() { Text = "<table border='0' ><tr><td>Name</td><td>Email</td><td>Job Title</td><td>Dept</td><td>Manager</td><td>EMP ID</td><td>Tel No</td><td>Mobile</td><td>Office</td><td>Home</td><td>Desc</td><td>Photo</td></tr>" });
                    foreach (SearchResult ent in results)
                    {
                        string userNameVal = ent.Properties["cn"][0].ToString();
                        string mailVal = null;
                        string jobTitleVal = null;
                        string deptVal = null;
                        string mgrVal = null;
                        string empIDVal = null;
                        string telNoVal = null;
                        string mobileVal = null;
                        string officeAddVal = null;
                        string profilePic = null;
                        string homeAddrVal = null;
                        string desc = null;
                        string nameVal= null;
                        string dispnameVal = null;
                        if (ent.Properties["mail"].Count > 0)
                        {
                            mailVal = ent.Properties["mail"][0].ToString();
                        }
                        if (ent.Properties["title"].Count > 0)
                        {
                            jobTitleVal = ent.Properties["title"][0].ToString();
                        }
                        if (ent.Properties["department"].Count > 0)
                        {
                            deptVal = ent.Properties["department"][0].ToString();
                        }

                        if (ent.Properties["manager"].Count > 0)
                        {
                            string mng = ent.Properties["manager"][0].ToString();
                            string[] setp = new string[1];
                            setp[0] = "OU"; //If your users are in a OU use OU     
                            if (mng.Contains("OU"))
                            {
                                mng = mng.Split(setp, StringSplitOptions.None)[0];
                                mng = mng.Replace("CN=", "");
                                mng = mng.TrimEnd(',');
                                mng = mng.Replace("\\, ", ", ");
                            }
                            mgrVal = mng;
                        }
                        if (ent.Properties["pager"].Count > 0)
                        {
                            empIDVal = ent.Properties["pager"][0].ToString();
                        }
                        if (ent.Properties["telephoneNumber"].Count > 0)
                        {
                            telNoVal = ent.Properties["telephoneNumber"][0].ToString();
                        }
                        if (ent.Properties["mobile"].Count > 0)
                        {
                            mobileVal = ent.Properties["mobile"][0].ToString();
                        }
                        if (ent.Properties["physicalDeliveryOfficeName"].Count > 0)
                        {
                            officeAddVal = ent.Properties["physicalDeliveryOfficeName"][0].ToString();
                        }
                        if (ent.Properties["thumbnailPhoto"].Count > 0)
                        {
                            profilePic = ent.Properties["thumbnailPhoto"][0].ToString();
                        }
                        if (ent.Properties["description"].Count > 0)
                        {
                            desc = ent.Properties["description"][0].ToString();
                        }
                        if (ent.Properties["streetAddress"].Count > 0)
                        {
                            homeAddrVal = ent.Properties["streetAddress"][0].ToString();
                        }
                        if (ent.Properties["name"].Count > 0)
                        {
                            nameVal = ent.Properties["name"][0].ToString();
                        }
                        if (ent.Properties["displayName"].Count > 0)
                        {
                            dispnameVal= ent.Properties["displayName"][0].ToString();
                        }

                       }
                        string text = string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td>{6}</td><td>{7}</td><td>{8}</td><td>{9}</td><td>{10}</td><td>{11}</td></tr>",
                        ent.Properties["cn"][0].ToString(), mailVal, jobTitleVal, deptVal, mgrVal, empIDVal, telNoVal, mobileVal, officeAddVal, homeAddrVal, desc, profilePic);

                        this.Controls.Add(new Literal() { Text = text });


                    }
                    this.Controls.Add(new Literal() { Text = "</table>" });

                }
            }
        });
        }
        catch (Exception ex)
        {
            this.Controls.Add(new Literal() { Text = ex.ToString() });
        }

Function GetDirectory:

    public static DirectoryEntry GetDirectoryEntry()
    {
        try
        {
            DirectoryEntry entryRoot = new DirectoryEntry("LDAP://RootDSE");
            string Domain = (string)entryRoot.Properties["DefaultNamingContext"][0];
            DirectoryEntry de = new DirectoryEntry();
            de.Path = "LDAP://" + Domain;
            de.AuthenticationType = AuthenticationTypes.Secure;
            return de;
        }
        catch
        {
            return null;
        }
    }

2) Another way to directly display records from AD using below code in a webpart on page load:

    DirectoryEntry entry;
    DirectorySearcher search;
    SearchResultCollection results;
    protected override void CreateChildControls()
    {
        try
        {
            System.Security.PermissionSet ps = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted);
            ps.Assert();

            Microsoft.SharePoint.SPServiceContext serviceContext = Microsoft.SharePoint.SPServiceContext.Current;
            UserProfileManager upm = new Microsoft.Office.Server.UserProfiles.UserProfileManager(serviceContext);
            this.Controls.Add(new Literal() { Text = "<table border='0' > <tr><td>Displayname</td><td>Name</td><td>Value</td></tr>" });
            ProfileSubtypePropertyManager pspm = upm.DefaultProfileSubtypeProperties;
            UserProfile profile = upm.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName);
            foreach (ProfileSubtypeProperty prop in pspm.PropertiesWithSection)
            {
                if (prop.IsSection)
                    this.Controls.Add(new Literal() { Text = string.Format("<tr><td colspan='3'><b>Section: {0}</b></td></tr>", prop.DisplayName) });
                else
                {
                    string text = string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>",
                        prop.DisplayName,
                        prop.Name,
                        profile[prop.Name].Value);

                    this.Controls.Add(new Literal() { Text = text });
                }
            }
            this.Controls.Add(new Literal() { Text = "</table>" });
        }
        catch (Exception ex)
        {
            this.Controls.Add(new Literal() { Text = ex.ToString() });
        }
        finally
        {
            System.Security.CodeAccessPermission.RevertAssert();
        }}

You will need to modify the code as your requirements. But hopefully the approach 1 will solve the purpose efficiently.

  • Is there any way to do this without coding?. I've done to follow this tutorial to import AD to Sharepoint 2013, but I don't know how to create a list contain these information in AD? : boostsolutions.com/blog/… – user3622351 Sep 24 '14 at 6:13
  • the option looks great. i need to try the one. but for now i have implemented the same programmatically. – Hardik Kothari Sep 24 '14 at 6:31
  • can you try it and show me the result. I'm new to Sharepoint @@ – user3622351 Sep 24 '14 at 6:33
  • that way its not working. need to deep dive into it. not getting the list created which it shows in the link – Hardik Kothari Sep 24 '14 at 8:41
  • So, can you show me step by step to do your way. you only give me a code, I don't know how to do with it. – user3622351 Sep 24 '14 at 9:12
2

Option 1: Use the Contact List Web Part available in SharePoint If you are a small organization, you can simply use an out of the box Web Part called Contacts to manage contact information. The beauty of this approach is that you can customize your Contacts Web Part with any columns/metadata that you wish. That means you can add all sorts of phone numbers, notes, other information and group/organize it in any way you wish on your SharePoint site or page.

Option 2: Create custom SharePoint Employee Directory The second option when it comes to SharePoint Employee Directory is to create custom sites/pages using Content Search Web part. This option works well when you have a larger organization and want to create an Employee Directory that allows you to filter the different properties using left-hand-side metadata criteria. You do need to be an advanced SharePoint User to create this sort of Directory.

Option 3. Use Office 365 Delve User Profile

1

You can leverage SharePoint Search to create a simple Company Directory. Here are some articles that will help you.

1) You can use any 'template', it would just require adding the right webparts to a page.

2) Here's a good tutorial on building a searchable People Directory: http://www.sharepointconfig.com/2013/05/how-to-create-a-simple-sharepoint-2013-people-directory/

3) Here's a good tutorial on configuring People Search: http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2013/01/03/how-to-set-up-people-search-in-sharepoint-2013.aspx

  • tks for your answer, but I got problem in the tutorial on building a searchable people dir . I see a list of staff of my company, but I can't view theirs profile (even my profile) by click in the name of this people – user3622351 Sep 25 '14 at 2:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.