A few days ago a coleague asked me to help him with a small program that generates a corporate email signature. The trick was that each user would have its own signature with the information being taken from its Active Directory account. At that time he was using a visual basic script that run from a shell and was using a XSL file for generating an HTML signature. It was an easy feat modifying the XSL to generate the wanted result but soon I hit a wall. How can you read a custom telephone
After scouring the net for a sollution I finnaly decided to use the QuickWatch feature of VisualStudio a little more in depth. What I found is that a DirectoryEntry has another property caller “otherTelephone” which is a collection of strings and of course my other telephone resided in the first position of that list.
Below is a snippet of my code:
DirectoryEntry oDE = new DirectoryEntry(“LDAP://contoso.local”, “contoso\\johndoe”, “qwerty”);
DirectorySearcher deSearch = new DirectorySearcher();
deSearch.SearchRoot = oDE;
deSearch.Filter = “(&(objectClass=user)(SAMAccountName=johndoe“))”;
deSearch.SearchScope = SearchScope.Subtree;
SearchResult results = deSearch.FindOne();
if (results != null)
{
System.DirectoryServices.ResultPropertyCollection userProps = results.Properties;
if (userProps["otherTelephone"].Count > 0)
{
string otherTelephone = userProps["otherTelephone"][0];
}
}



Entries (RSS)