namespace SignatureCreator
{
class Program
{
static void Main(string[] args)
{
string delimiter = ",";
// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
// find currently logged in user
UserPrincipal up = UserPrincipal.Current;
string displayName = up.DisplayName;
string title = up.Description;
string phoneNumber = up.VoiceTelephoneNumber;
string[] userName = displayName.Split(new string[] { delimiter }, StringSplitOptions.None);
string firstName = userName[1];
string lastName = userName[0];
firstName = firstName.Substring(1);
firstName = firstName.ToUpper();
lastName = lastName.ToUpper();
Console.WriteLine(firstName +" "+ lastName);
Console.WriteLine(title);
Console.WriteLine(phoneNumber);
DirectoryEntry entry = up.GetUnderlyingObject() as DirectoryEntry;
System.DirectoryServices.PropertyCollection props = entry.Properties;
/*
*
*/
foreach (string propName in props.PropertyNames)
{
if (entry.Properties[propName].ToString() == "mobile")
{
Console.WriteLine(propName + " = " + entry.Properties[propName].Value);
}
else
{
Console.WriteLine(propName + " = NULL");
}
}
Console.ReadKey();
StringBuilder sb = new StringBuilder();
}
}
}
我正在尝试遍历活动目录信息以查找用户的手机号码。但我不知道如何循环并返回它。即使我只是评估propname == mobile,它也不会返回true。我究竟做错了什么?