There is a naming violation - Creating a contact object

J

jgfreitas

Hi Experts...

Anyone could help me?
I´m getting this error when I try to create a new contact object on
AD / Exchange using special characters on Common Name:

{"There is a naming violation." }
{System.Runtime.InteropServices.COMException}
_COMPlusExceptionCode: -532459699
_HResult: -2147016649
_message: There is a naming violation.
Source: System.DirectoryServices

The code I´m using is below:

public void CriarContact

(string accountBusca, string fullName, string firstName,
string lastName,
string initials, string displayName, string ag, string
mail, string company, string telephoneNumber,
string country, string state, string city, string manager,
string notes, string alias, string ou
)
{
try
{

DirectoryEntry de = null;
if(!ou.Equals(String.Empty))
{
string path = Entry.Path.Substring(0,
Entry.Path.ToUpper().IndexOf("DC=")) + ou;
DirectoryEntry deOU = new
DirectoryEntry(path);

de = deOU.Children.Add("CN=" +
accountBusca, "Contact");
}
else
{
de = Entry.Children.Add("CN=" +
accountBusca, "Contact");
}

de.Properties["displayName"].Add(displayName);
de.Properties["givenName"].Add(firstName);
de.Properties["sn"].Add(lastName);
de.Properties["initials"].Add(initials);

if (!mail.Trim().Equals(string.Empty))
de.Properties["mail"].Add(mail);

if (!alias.Trim().Equals(string.Empty))

de.Properties["mailNickName"].Add(alias);

DirectoryEntry deManager =
ObterUsuarioPorAccount(manager);

de.Properties["manager"].Add(deManager.Properties["distinguishedName"].Value.ToString());

de.Properties["info"].Add(notes);

IMailRecipient oMB =
(IMailRecipient)de.NativeObject;
oMB.AutoGenerateEmailAddresses = false;
oMB.Alias = accountBusca;
oMB.SMTPEmail = mail;
de.Properties["TargetAddress"].Add("SMTP: " +
mail);
de.CommitChanges();
de.Close();
}


Is this possible? (to use special characters on the common name of the
object)
I found this Microsoft article about this subject, but the server
where I´m running the app is Win 2003... so I can't apply the
hotfix...

http://support.microsoft.com/kb/834541/en-us

I would appreciate any help...
Tnks
Juliana
 
R

Richard Mueller [MVP]

I discuss characters that must be escaped in AD in this link:

http://www.rlmueller.net/CharactersEscaped.htm

Briefly, the following characters must be escaped:

, \ / # + < > ; " =

They are escaped with the backslash "\" escape character. For example:

"cn=Smith\, Jim"

If you are specifying Common Names, you may want to replace all instances of
"," with "\,". Similar for the other characters.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

Hi Experts...

Anyone could help me?
I´m getting this error when I try to create a new contact object on
AD / Exchange using special characters on Common Name:

{"There is a naming violation." }
{System.Runtime.InteropServices.COMException}
_COMPlusExceptionCode: -532459699
_HResult: -2147016649
_message: There is a naming violation.
Source: System.DirectoryServices

The code I´m using is below:

public void CriarContact

(string accountBusca, string fullName, string firstName,
string lastName,
string initials, string displayName, string ag, string
mail, string company, string telephoneNumber,
string country, string state, string city, string manager,
string notes, string alias, string ou
)
{
try
{

DirectoryEntry de = null;
if(!ou.Equals(String.Empty))
{
string path = Entry.Path.Substring(0,
Entry.Path.ToUpper().IndexOf("DC=")) + ou;
DirectoryEntry deOU = new
DirectoryEntry(path);

de = deOU.Children.Add("CN=" +
accountBusca, "Contact");
}
else
{
de = Entry.Children.Add("CN=" +
accountBusca, "Contact");
}

de.Properties["displayName"].Add(displayName);
de.Properties["givenName"].Add(firstName);
de.Properties["sn"].Add(lastName);
de.Properties["initials"].Add(initials);

if (!mail.Trim().Equals(string.Empty))
de.Properties["mail"].Add(mail);

if (!alias.Trim().Equals(string.Empty))

de.Properties["mailNickName"].Add(alias);

DirectoryEntry deManager =
ObterUsuarioPorAccount(manager);

de.Properties["manager"].Add(deManager.Properties["distinguishedName"].Value.ToString());

de.Properties["info"].Add(notes);

IMailRecipient oMB =
(IMailRecipient)de.NativeObject;
oMB.AutoGenerateEmailAddresses = false;
oMB.Alias = accountBusca;
oMB.SMTPEmail = mail;
de.Properties["TargetAddress"].Add("SMTP: " +
mail);
de.CommitChanges();
de.Close();
}


Is this possible? (to use special characters on the common name of the
object)
I found this Microsoft article about this subject, but the server
where I´m running the app is Win 2003... so I can't apply the
hotfix...

http://support.microsoft.com/kb/834541/en-us

I would appreciate any help...
Tnks
Juliana
 
J

jgfreitas

I discuss characters that must be escaped in AD in this link:

http://www.rlmueller.net/CharactersEscaped.htm

Briefly, the following characters must be escaped:

, \ / # + < > ; " =

They are escaped with the backslash "\" escape character. For example:

"cn=Smith\, Jim"

If you are specifying Common Names, you may want to replace all instancesof
"," with "\,". Similar for the other characters.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab -http://www.rlmueller.net
--


Hi Experts...

Anyone could help me?
I´m getting this error when I try to create a newcontactobjecton
AD / Exchange using special characters on Common Name:

{"Thereis anamingviolation." }
{System.Runtime.InteropServices.COMException}
_COMPlusExceptionCode: -532459699
_HResult: -2147016649
_message:Thereis anamingviolation.
Source: System.DirectoryServices

The code I´m using is below:

public void CriarContact

(string accountBusca, string fullName, string firstName,
string lastName,
string initials, string displayName, string ag, string
mail, string company, string telephoneNumber,
string country, string state, string city, string manager,
string notes, string alias, string ou
)
{
try
{

DirectoryEntry de = null;
if(!ou.Equals(String.Empty))
{
string path = Entry.Path.Substring(0,
Entry.Path.ToUpper().IndexOf("DC=")) + ou;
DirectoryEntry deOU = new
DirectoryEntry(path);

de = deOU.Children.Add("CN=" +
accountBusca, "Contact");
}
else
{
de = Entry.Children.Add("CN=" +
accountBusca, "Contact");
}

de.Properties["displayName"].Add(displayName);
de.Properties["givenName"].Add(firstName);
de.Properties["sn"].Add(lastName);
de.Properties["initials"].Add(initials);

if (!mail.Trim().Equals(string.Empty))
de.Properties["mail"].Add(mail);

if (!alias.Trim().Equals(string.Empty))

de.Properties["mailNickName"].Add(alias);

DirectoryEntry deManager =
ObterUsuarioPorAccount(manager);

de.Properties["manager"].Add(deManager.Properties["distinguishedName"].Valu­e.ToString());

de.Properties["info"].Add(notes);

IMailRecipient oMB =
(IMailRecipient)de.NativeObject;
oMB.AutoGenerateEmailAddresses = false;
oMB.Alias = accountBusca;
oMB.SMTPEmail = mail;
de.Properties["TargetAddress"].Add("SMTP: " +
mail);
de.CommitChanges();
de.Close();
}

Is this possible? (to use special characters on the common name of theobject)
I found this Microsoft article about this subject, but the server
where I´m running the app is Win 2003... so I can't apply the
hotfix...

http://support.microsoft.com/kb/834541/en-us

I would appreciate any help...
Tnks
Juliana

Hello Richard,

It works using backslash to escape the characters...

Thanks a lot!
Best regards
Juliana
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top