【发布时间】:2024-04-25 23:55:01
【问题描述】:
我想在我们的 AD 中的特定 OU 中创建一个带有一些属性的联系人对象:
sn、givenName、mail、description、displayname、proxyAddresses 和 targetaddress。
我找到了很多示例,如何使用 C# 在 Active Directory 中为联系人对象设置属性,并且我能够创建具有除“targetaddress”之外的所有属性的对象。
有人可以为我指出正确的方向吗?谢谢!
public void CreateContact2(string Vorname, string Nachname, string EmailAdresse, string Beschreibung, string myDomainPath)
{
string CN = Vorname + " " + Nachname;
string mailNickName = EmailAdresse.Remove(EmailAdresse.IndexOf("@"));
string EmailAdresse2 = "SMTP:" + EmailAdresse;
DirectoryEntry directoryEntry;
try
{
directoryEntry = new DirectoryEntry("LDAP://myDomainPath")
directoryEntry.RefreshCache();
DirectoryEntry contact = directoryEntry.Children.Add("CN=" + CN, "Contact");
contact.Properties["sn"].Value = Nachname;
contact.Properties["givenName"].Value = Vorname;
contact.Properties["mail"].Value = EmailAdresse;
contact.Properties["description"].Value = Beschreibung;
contact.Properties["displayName"].Value = Nachname + ", " + Vorname;
contact.Properties["proxyAddresses"].Add(EmailAdresse2);
contact.Properties["targetaddress"].Value = EmailAdresse2;
contact.CommitChanges();
}
catch (Exception e)
{
// Do some error processing
var msg = e.Message.ToString();
Console.WriteLine("Fehler in Funktion CreateContact():" + msg);
}
}
如果我在没有 targetaddress-Attribute 的情况下创建 Contact-Object 时,它会创建得很好
但有了它我是
获取 System.Runtime.InteropServices.COMException:“指定的 目录服务属性或值不存在”
失败。有什么想法吗?
【问题讨论】:
-
不区分大小写吧?
标签: c# active-directory contacts