Get SIP address from active directory





5.00/5 (2 votes)
SIP address from active directory
The below code will be used to get the SIP address from the active directory. SIP address is commonly used in office communicator server. I have used this code to fetch the SIP address. Based on the SIP address, we have applied provisioning on office communicator server 2007.
private string GetSIPAddress(string email)
{
DirectoryEntry directoryEntry =
new DirectoryEntry(ConfigurationManager.AppSettings["LDAPPATH"]);
string resultValue = "";
using (HostingEnvironment.Impersonate())
{
DirectorySearcher directorySearcher = new DirectorySearcher(directoryEntry);
directorySearcher.Filter = string.Format("(&(objectClass=user)(objectCategory=user) (mail={0}))", email);
directorySearcher.PropertiesToLoad.Add("msRTCSIP-PrimaryUserAddress");
SearchResult result = directorySearcher.FindOne();
if (result != null)
{
if (result.Properties["msRTCSIP-PrimaryUserAddress"] != null)
{
resultValue = result.Properties["msRTCSIP-PrimaryUserAddress"][0].ToString();
resultValue = "'" + resultValue + "'";
}
}
};
return resultValue;
}