Search This Blog

Friday, June 17, 2016

User Information List in SharePoint 2013

What is User Information List?
As per the Name SharePoint User Information List stores information about a user by having some metadata set up for the user. Some examples are User Picture, Email, DisplayName, LoginName etc. For a complete list of fields, see further down this blogpost under "User Information List Fields".
When a user get added in User Information List?
When we grant any user permissions to a user, they are added automatically to the hidden User Information list a new item will be created in the User Information List storing some information about the user.
Even though if we grant access to any active directory group the group gets added to the hidden User Information list as well but the user does not get added until they access the site. (As an example, I granted an AD group permissions to my site & only the AD group showed up in the hidden User Information list not the users
It has been changed little bit in SharePoint 2013. As it shows user in list as soon as I give them permission to site regardless of they logon or not
Where the User Information details are used in SharePoint
When a user add/create or edit an item, documents or pages SharePoint will display the Created By or Last modified by details for the users and these all comes from the SharePoint User Information List
URL for User Information List SP 2010 ?
http://siteurl/_catalogs/users/detail.aspx - If you want to see the detail view of only Users in the list.
http://siteurl/_catalogs/users/simple.aspx - The blow URL will show the simple view of only Users in the List
http://siteurl/_catalogs/users/allgroups.aspx - This will provide all the groups without users available in Site.
URL for User Information List SharePoint 2013?
http://siteurl/_catalogs/users/detail.aspx - If you want to see the detail view of only Users in the list.
http://siteurl/_catalogs/users/simple.aspx - The blow URL will show the simple view of only Users in the List
http://siteurl/_catalogs/users/allgroups.aspx - This will provide all the groups without users available in
http://siteurl/_layouts/15/people.aspx?MembershipGroupId=0
URL for User Information List SharePoint online, O365

Or
http://siteurl/_layouts/15/people.aspx?MembershipGroupId=0
Note : /_catalogs folder is not mapped as virtual folder in IIS, like /_layouts, /settings.aspx or other application pages that we have in SharePoint site etc, i.e. it will work only on the root site.
Here the important thing is that these endless Users, AllUsers, SiteUsers, etc properties of SPWeb and SPSite, which may return different results depending on the context site, should not mislead you: users are created on site collection level.   
User Information List is a special one but still is a list and is bound to the web scope. So it is stored only in the root web of each site collection and you wouldn't find it in any subweb
In theory this list should be updated with user profile synchronization as well, but at first SharePoint may be used without user profiles, and second because of a lot of bugs in this process, on practice the most reliable way to force synchronization between user profiles and user information list is to delete user from the list explicitly and call SPWeb.EnsureUser(). We had similar situation and it was the only method which really worked (in our case it was more tricky: samAccountName of the user account in AD was changed, but as SID remained the same, Sharepoint still showed old account name).
If there is some users who’s details are showing differently in SharePoint than its AD value
You can try to sync the user profile with user Information List by below given Power shell script.
To fix the issue run the PowerShell as below. abcDomainName\pqrUserLoginId ---> abc is the domain and pqr is the user login.
$web=Get-SPWeb ...web URL...
$web|Set-SPUser -identity "abcDomainName\pqrUserLoginId" -SyncFromAD

The problem is the UserInformationList is stored in AllUserData table. This is not the UserInfo table. It is absolutely different portion of data. You can see its data by navigating to http://<SiteCollectionUrl>/_catalogs/users/detail.aspx. It is the site (Web scope) level data and the UserInformationList (hidden list) is created for the Root Web of each site collection. While UserInfo stores data of the site collection level. Information in UserInfo table can be different fromUserInformationList. So if i get the user from PowerShel I get the right display name.

$web = Get-SPWeb -Identity 'WebUrl'
$user = $web | Get-SPUser -Identity 'login'
$user.DisplayName

If I Remove users from User Information List


We can remove a user from the User Information List (UIL) in a site collection from SharePoint 2010 and 2013. SharePoint stores user information in the UIL to extract data when this user is being searched by the people picker, the people picker extracts information from multiple locations:
– The User Information List
– Active Directory

The people picker does not extract information from the User Profile Service Application (UPSA). The UPSA syncs information from the AD and updates the UIL but it does not delete the user from it.

For example if I will delete myself from the Active Directory and navigate back to SharePoint to see what happened.
– I can no longer log on with “myLogInName”
– I can still find “myLogInName” with the people picker.
– The permissions are still visible
I want to delete myLogInName user from the Site Collection so this user won’t be found by the people picker and the permissions will be deleted.

Solution
I can’t just click on the user and delete him because I’ll be redirected to the My Site (the My Site will be scheduled for deletion in 14 days by the My Site Cleanup Timer Job).
You will have to add the following right behind the URL
SharePoint 2010
<URL>/_layouts/people.aspx?MembershipGroupId=0

and click on “Actions –> Delete Users from Site Collection
After that
I can now
– no longer log on with “myLogInName”
– no longer find him using the people picker
– no longer find his permissions because they have been deleted
Downside is that you’ll receive the following error while clicking on this user at documents

With the following information from the ULS Viewer
System.ArgumentException: User cannot be found.
at Microsoft.SharePoint.SPList.GetItemById(String strId, Int32 id, String strRootFolder, Boolean cacheRowsetAndId, String strViewFields, Boolean bDatesInUtc)
at Microsoft.SharePoint.SPContext.get_Item()

Deleting users from UIL’s in bulk and across Site Collections
Please read the following blog from Nico Martens if you would like to delete users in bulk with PowerShell.
http://sharepointrelated.com/2012/10/11/remove-bulk-users-from-user-information-list-people-picker/

Timer Job that is working behind the User Information List?
To synchronize the User Profile user Data with user Information List there are two timer jobs that are responsible
  1. 1.      User Profile to SharePoint Quick Sync and
  2. 2.      User Profile to SharePoint Full Sync,
Can I set Alert on SharePoint User information list? Or Can I Track changes to the SharePoint User Information list.
How do you track the changes in "User Information List" without using any custom code? One way is to enable auditing under site collection administration for "Editing users and permissions". However this add an extra load to the database and may result in performance issues. Moreover his requirement was to track only when a user is added or removed from site collection. 
Another approached is to setup alerts. However, the User Information List does not have any option to setup alerts or go to setting etc as normal lists. So how can we configure alerts on the list?
1. Our first requirement was to get the GUID. To get this we queried dbo.Lists table in the content database holding this site collection.

2. The query should be: Select tp_ID From Lists with(NoLock)where tp_Title = 'User Information List'

3. Make a note of this ID, Now go to any other list in the top site in your site collection and click on Alert Me under Actions.

4. In the next page in URL remove the contents after ?List= and add the GUID noted in step 3.

5. Press enter and now you will find that the fields are populated with User Information List and you can create the alerts.
It is not possible to add event handlers to the user info list ?
 No, we cannot attach any event handler to User Information List. Please check the MS details on that on this article (http://msdn.microsoft.com/en-us/library/aa979520.aspx), we know that  “Lists:List events do not fire on the UserInfo list.”
       Another asynchronous was discussed in this post below:       we can think to create a service to monitor the change inUserInfo list, or get the modification logs from audit information is also a solid alternative.

Please see this following thread:

How user Information list is linked with SharePoint User Profile Service?
To keep all the information in the user information lists up to data with User profile and user Information list is a task that is handled by the Profile Synchronization and the Quick Profile Synchronization timer jobs. By default the first job runs once every hour, the second one runs every couple of minutes and is incremental. The first time user data is replicated from the user profile to the user information list of a site a full update is needed. So the Profile Synchronization job needs to run in order to get the data replicated to the site and this may take up to an hour. If information about a user is already stored in the user information list and the information changes in the user profile it will be synchronized with the data in the site collection by the  Quick Profile Synchronization job.
You can also kick off the profile synchronization jobs by running the stsadm sync command.
  stsadm -o sync

If you believe that information is not synced between the user profiles and the user information lists in one or more sites you can request a list of content databases that have not been synchronized for x number of days by using the following stsadm sync command.
 stsadm -o sync -listolddatabases <x number of days>
 If one or more content databases show up in this list you can clean up the sync list so they can be added to the list again.
 stsadm -o sync -deleteolddatabases <x number of days>
 You can also use the sync command to change the schedule for the synchronization job.
For more information on the stsadm sync command have a look here http://technet.microsoft.com/en-us/library/cc263196.aspx.
To synchronize the User Profile user Data with user Information List there are two timer jobs that are responsible
  1. 3.      User Profile to SharePoint Quick Sync and
  2. 4.      User Profile to SharePoint Full Sync,
That synchronize the User Profile database information with the UIL. Sometimes this stops working (properly) and in that case you need to run:
stsadm -o sync -listolddatabases 0
stsadm -o sync -deleteolddatabases 0
The first command will list Content Databases that haven't had the UPA -> UIL sync occur in 0 or more days. The second command will delete the records corresponding to those databases (it doesn't delete databases/end user data).
If still the issue is there you can delete the user from user Information list and run the user profile sync again to fix the issue.
How to access User information list using Server Object model?
// Get the List Object for User Information List
SPList userInformationList = SPContext.Current.Web.SiteUserInfoList;
// Get the Object of current logged in user
SPUser user = SPContext.Current.Web.EnsureUser(@"web");
// Here is actual User Information is within this SPListItem
SPListItem userItem = userInformationList.Items.GetItemById(user.ID);
The above code will give you the SPListItem object which links to the currently logged in user (the one executing the request) and you have almost all the details about the user you can play around it and user it further.
You can then work with the SPListItem object like normal to get or set the properties like this:
string userPictureURL = userItem["Picture"].ToString();


How to access User Information list using Client object model?
Here is the example of to get current log in user Id and show user Information by fetching from user Information list.
var contextObj = new SP.ClientContext.get_current();
    var webObj = contextObj.get_web();

    var userInfoListObj = webObj.get_siteUserInfoList();

    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'ID\' />' +
                                '<Value Type=\'Number\'>' + userId + '</Value></Eq>' +
                                '</Where></Query><RowLimit>1</RowLimit></View>');

    this.userInfoListObj= userInfoListObj.getItems(camlQuery);

    contextObj.load(this.userListItem);

    contextObj.executeQueryAsync(
            Function.createDelegate(this, onSucceeded),
            Function.createDelegate(this, onFailed));

The onSucceeded function is called when the query runs successfully, otherwise the onFailed function will be executed.
function onSuceeded(sender, eventArgs)
{
        var item = this.userListItem.itemAt(0);
        var name = item.get_item('Name');
        var userName = "Name";

        if (name) {
            userName = name;
        }

        alert(userName);
}

We need to execute the code after SP.js is loaded SP.SOD.executeOrDelayUntilScriptLoaded(LoadUserInfo, 'SP.js');
How to access User information list for SharePoint online Site?
/_catalogs/users/detail.aspx is work in both Onpremise and SharePoint Online
How to access User Information list using powershell scripts.
You can write a PowerShell script(named ListWebUserInformationListItems.ps1) as following:
 # Run with SharePoint 2010 Management Shell
$webUrl = Read-Host "Enter the web url"
$web = Get-SPWeb $webUrl
$list = $web.Lists["User Information List"]
$query = New-Object Microsoft.SharePoint.SPQuery
$queryCamlString = '<Query><OrderBy><FieldRef Name="Title" Ascending="True" /></OrderBy></Query>'
$query.Query = $queryCamlString
$userInformationListItems = $list.GetItems($query)
foreach($userInformationListItem in $userInformationListItems)
{
    echo $userInformationListItem.Title
}



****************************************************************************************************************

update user information list

SPWeb web = properties.OpenWeb();
           web.AllowUnsafeUpdates = true;

           SPList list = web.Lists["Távollétek"];
           SPListItem item = properties.ListItem;

           SPSite site = new SPSite("http://sp2010/sites/demo");
           SPWeb kezdo = site.OpenWeb();
           SPList felhasznalok = kezdo.Lists["User Information list"];
           
           
           string userReszleg = string.Empty;
           string nev = item["Name"].ToString();
           foreach (SPListItem felList in felhasznalok.Items)
           {
               if (nev == felList["Name"].ToString())
               {
                   userReszleg = felList["Department"].ToString();
               }
           }
           item["Department"] = userReszleg.ToString();
           item.Update();
           this.EventFiringEnabled = true;
 
 

SharePoint User Profiles - Internal Names

Two types of User Profiles:
1. WSS Profile - can be accessed from Welcome User > My Settings page (_layouts/userdisp.aspx?.......)


User Information List
Display Name
Internal Name
AccountName
First nameFirstName
Last nameLastName
NameTitle
Work phoneWorkPhone
OfficeOffice
DepartmentDepartment
TitleJobTitle
Work e-mailEMail
User nameUserName


2. MOSS profile - can be accessed from My Site (../Person.aspx?....). The MOSS profiles are created when users are imported into the system from AD or LDAP.


SSP User Profile
Display Name
Internal Name
Account nameAccountName
First nameFirstName
Last nameLastName
NamePreferredName
Work phoneWorkPhone
OfficeOffice
DepartmentDepartment
TitleTitle
Work e-mailWorkEmail


Basically, there are two MOSS Timer jobs that control the replication of the user profiles per web application. These jobs can be found from Central Administration -> Operations -> Timer Job definitions.

1. Profile Synchronization - updates the WSS profiles.
2. Quick Profile Synchronization - updates the MOSS profiles.

******************************************************************************************************************
How to Access and Update User Information List Programmatically.

To acces the hidden User Information List list of a SharePoint site (only accessible by administrators), the best way is to use the SiteUserInfoList property of the SPWeb object as in the following example:



// Button1- title and Internal name of User Information list



protected void Button1_Click(object sender, EventArgs e)

        {



            DataTable dtt = new DataTable();

            dtt.Columns.Add("Title ", typeof(string));

            dtt.Columns.Add("InternalName", typeof(string));





            SPSecurity.RunWithElevatedPrivileges(delegate()

            {

                using (SPSite site = new SPSite("http://abc/"))

                {

                    using (SPWeb web = site.OpenWeb())

                    {

                        SPList listUserInfo = web.SiteUserInfoList;

                        SPFieldCollection fieldColl = listUserInfo.Fields;

                        foreach (SPField field in fieldColl)

                        {

                            Console.WriteLine("Name:{0} - Type:{1}", field.Title, field.TypeAsString);



                            dtt.NewRow();

                            //dtt.Rows.Add(words[i], words2[i], words3[i]);

                            //dtt.Rows.Add(a, b, c, txt4,txt5,txt6,txt7,txt8,txt9,txt10);

                            dtt.Rows.Add(field.Title, field.InternalName);

                        }



                        GridView1.DataSource = dtt;

                        GridView1.DataBind();

                    }

                }

            });

        }



// Button2 – fetch record from user information list





        protected void Button2_Click(object sender, EventArgs e)

        {



            DataTable dt = new DataTable();

            dt.Columns.Add("ID", typeof(string));

            dt.Columns.Add("Title", typeof(string));

            dt.Columns.Add("User Name", typeof(string));

            dt.Columns.Add("Email", typeof(string));





            using (SPSite mySiteCollection = new SPSite("http://abc/"))

                {

                    using (SPWeb mySite = mySiteCollection.OpenWeb(mySiteCollection.RootWeb.ID))

                    {

                        SPList usersList = mySite.SiteUserInfoList;



                        SPListItemCollection oSpListCln = usersList.Items;



                        //iterate through all the items in itemcollection object

                        foreach (SPListItem item in oSpListCln)

                        {

                            dt.NewRow();

                           

     dt.Rows.Add(item["ID"], item["Title"], item["UserName"], item["EMail"]);

                        }



                        GridView2.DataSource = dt;

                        GridView2.DataBind();

                    }

                }

        }





// Button3 – update record from user information list


        protected void Button3_Click(object sender, EventArgs e)
        {



            using (SPSite mySiteCollection = new SPSite("http://abc/"))

            {

                using (SPWeb mySite = mySiteCollection.OpenWeb(mySiteCollection.RootWeb.ID))

                {

                    mySite.AllowUnsafeUpdates = true;

                    SPList usersList = mySite.SiteUserInfoList;



//in ID(column) have record which contain 5(value) number                   



SPListItem item = usersList.GetItemById(Convert.ToInt32("5"));



                    item["EMail"] = "abc@hotmail.com";



                    item.Update();

                }

            }

  }


Synchronize Active Directory Information with Sharepoint Foundation 2013 User Profiles

You might be wondering why should I do this when Sharepoint can do this already though User Profile Synchronization, well that is partly true because in Sharepoint Foundation 2013 and even on 2010 it is not available.  Having said that there will always be a way and that’s what are trying to achieve on this article, to synchronize Active Directory Information with Sharepoint User Profile by doing some coding.  This can be achieved in multiple ways, you can do Powershell, you can create a Sharepoint feature or develop a standalone application, we will do the latter as for me its more flexible and manageable.
01 Ad and Sharepoint
Now lets start but before doing so lets lay out some ground work and give some explanation on how to we go about on this one.
Did you know that Sharpoint stores user profiles in a list as well?  It’s sort of hidden but in case you did not know you can locate it at:
And it will look like this
02 User List


But something is different, unlike normal lists it does not give you the tabs to manipulate the list or its view but that does not stop us in doing so as it is just a web part in a page, having said that you can still edit the page.
03 Edit Page
and edit the web part
04 Edit The Web Part
then edit the current view
05 Edit the current view
and there you are
06 View Edit

free to change how your view looks like.
That does not end there, you can also edit the list by adding column of your choice.  It’s not straightforward though as you need to know your List Id by checking it in the URL while you in the view property page.
07 List Id
Now copy that and combine it with the URL below to view your List Properties
And whoalla! you can now edit your list.
08 Manage List
So now lets say we add Description, Office and Company which is not there by default.
09 Update List
Once saved you can now see it on the view
10 It shows now on the view
Now that you know that the user profiles are saved on a list and you can modify the structure of it let’s do some coding and map our Active Directory with Sharepoint User Data.  For this example we will map the common and the most logical fields we usually use.
11 Mapping
Although it shows the proper name on the view the field names might not be the same, so if you run the codes below and investigate what the field names are it would look like this.
11a Mapping Sp
So make sure you map it to the correct Sharepoint and Active Directory fields/columns, for our example it will be like this.
View Labels
Sharepoint Name
Active Directory Name
NameTitledisplayName
E-MailEMailmail
Job TitleJobTitletitle
DepartmentDepartmentdepartment
Mobile NumberMobilePhonemobile
DDIDDItelephoneNumber
SIP AddressSIPAddressipPhone
DescriptionDescriptiondescription
OfficeOfficephysicalDeliveryOfficeName
CompanyCompanycompany
Now lets start coding.  What we will do first is a simple listing of all Site Users, to do that copy and paste the codes below.
private static void GetAllSiteUsers()
{
    // Starting with ClientContext, the constructor requires a URL to the server running SharePoint. 
    var sharepointContext = new ClientContext("http://yoursharepointurl/");
 
    //Get Web Context
    var sharepointList = sharepointContext.Web.SiteUserInfoList;
 
    var camlQuery = new CamlQuery();
 
    var userList = sharepointList.GetItems(camlQuery);
    sharepointContext.Load(userList);
    sharepointContext.ExecuteQuery();
 
    foreach (ListItem user in userList)
    {
               
    }
}
Run it and lets see your first data, the first user that will appear is the one who set up your Sharepoint Instance, which means you are safe to assume that it is a real user.
12 Filtering Users
Place a breakpoint and investigate your results.  If you notice when you run the code it will give you all the List Items and in our example we have 2399 items, we need to filter it further because the whole list contains Users, Active Directory Groups and Sharepoint Groups.  What we need to sync only are the Users so we need to identify which are the users somehow.
After looking at my example I have two Field values that I can use, first is the ContentTypeId which if you further investigate is common for all Users other entities have a different ContentTypeId.  Another is the Name where all users will have a Claims Authentication Code and Domain Prefix iei:0#.w|YourDomainUserName other entities such as group is prefixed as c:0+.w|  followed by and SID.
Now we know how to filter lets apply that to the CAML Query and further filter our results.
private static void GetAllSiteUsersFilteredByType()
{
    // Starting with ClientContext, the constructor requires a URL to the server running SharePoint. 
    var sharepointContext = new ClientContext("http://yoursharepointurl/");
 
    //Get Web Context
    var sharepointList = sharepointContext.Web.SiteUserInfoList;
 
    //Prefix for all users
    string userType = "i:0#.w|";
 
    var camlQuery = new CamlQuery();
    camlQuery.ViewXml = @"<FieldRef Name='Name' />" + userType + "</Value></Contains></Where></Query></View>";
 
    var userList = sharepointList.GetItems(camlQuery);
    sharepointContext.Load(userList);
    sharepointContext.ExecuteQuery();
 
    foreach (ListItem user in userList)
    {
 
    }
}
13 Filtered
Now you will see we have lesser result count as we only get the real users.
Let’s do the synchronization Part!
By now you know how to get all that users now we need to search for the same user in Active Directory get its information and overwrite the ones in Sharepoint.  The codes below is complete but I just created them in one class as a console application, it’s up to you how you want to use them.
The codes also takes into consideration that service user you will be using have full rights on Active Directory and is in the Site Collection Administrators Group on Sharepoint.
using Microsoft.SharePoint.Client;
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
 
namespace Sharepoint_User_and_Active_Directory_Sync
{
    static class Program
    {
        //If you're using claims authentication, this defines a user on a domain
        const string userType = "i:0#.w|";
        //If you're not using claims authentication, this defines a user on a domain
        //const string userType = @"YourDomain"; 
 
        const string domain = "your.sharepoint.com";
        const string rooOrganizationalUnit = "DC=your,DC=sharepoint,DC=com";
        const string adDomain = "YOURDOMAIN";
        const string adUserName = "YourServiceUser";
        const string adPassword ="YourServiceUserPassword";
 
        static void Main(string[] args)
        {
 
            // Starting with ClientContext, the constructor requires a URL to the server running SharePoint. 
            var sharepointContext = new ClientContext("http://yoursharepointurl/");
            sharepointContext.Credentials = new System.Net.NetworkCredential(adUserName, adPassword, adDomain);
 
            //Get Site Users Lists
            var sharepointList = sharepointContext.Web.SiteUserInfoList;
            
            //Filter User List by CAML Query
            var camlQuery = new CamlQuery();
            camlQuery.ViewXml = @"<FieldRef Name='Name' />" + userType + "</Value></Contains></Where></Query></View>";
            var userList = sharepointList.GetItems(camlQuery);
            sharepointContext.Load(userList);
            sharepointContext.ExecuteQuery();
 
            //Loop Through Each User
            foreach (ListItem user in userList)
            {
                //Lets remove the Claims Authentication Prefix
                var userName = user["Name"].ToString().Replace(userType, "");
 
                //Get the User Details from Active Directory
                UserPrincipal userPrincipal = GetUser(userName);
 
                //if User Principal Exists
                if (userPrincipal != null)
                {
                    user["Title"] = userPrincipal.DisplayName;
                    user["EMail"] = userPrincipal.EmailAddress;
                    user["Description"] = userPrincipal.Description;
                    user["DDI"] = userPrincipal.VoiceTelephoneNumber;
 
                    //Unrepresented AD Attributes in User Principal, we have to use 
                    //our own extension method called GetProperty to retrieve AD Value
                    user["JobTitle"] = userPrincipal.GetProperty("title");
                    user["Department"] = userPrincipal.GetProperty("department");
                    user["MobilePhone"] = userPrincipal.GetProperty("mobile");
                    user["SipAddress"] = userPrincipal.GetProperty("ipPhone");
                    user["Office"] = userPrincipal.GetProperty("physicalDeliveryOfficeName");
                    user["Company"] = userPrincipal.GetProperty("company");
 
                    //Update User
                    user.Update();
 
                    //Commit Changes
                    sharepointContext.ExecuteQuery();
                }
            }
        }
 
        /// <summary>
        /// Gets the base principal context
        /// </summary>
        /// <returns>Retruns the PrincipalContext object</returns>
        private static PrincipalContext GetPrincipalContext()
        {
            PrincipalContext principalContext;
 
            principalContext = new PrincipalContext(ContextType.Domain, domain, rooOrganizationalUnit, ContextOptions.Negotiate, adDomain + @"" + adUserName, adPassword);
 
            return principalContext;
        }
 
        /// <summary>
        /// Gets a certain user on Active Directory
        /// </summary>
        /// <param name="userName">The username to get</param>
        /// <returns>Returns the UserPrincipal Object</returns>
        private static UserPrincipal GetUser(string userName)
        {
            try
            {
                var principalContext = GetPrincipalContext();
 
                var userPrincipal = UserPrincipal.FindByIdentity(principalContext, userName);
                return userPrincipal;
            }
            catch
            {
                return null;
            }
        }
 
        /// <summary>
        /// Gets the AD Attributes not represented in UserPrincipal
        /// </summary>
        /// <param name="principal">The User Principal Object</param>
        /// <param name="property">The property name you want to retrieve</param>
        /// <returns></returns>
        private static string GetProperty(this UserPrincipal principal, string property)
        {
            var directoryEntry = principal.GetUnderlyingObject() as DirectoryEntry;
 
            if (directoryEntry.Properties.Contains(property))
            {
                return directoryEntry.Properties[property].Value.ToString();
            }
            else
            {
                //Property not exisiting return empty strung
                return string.Empty;
            }
        }
    }
}


No comments:

Post a Comment