Click here to Skip to main content
15,886,802 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi I have a Problem when I try give value using the function

C#
public string AttributeValuesSingleString
    (string attributeName, string objectDn)
{
    string strValue;
    DirectoryEntry ent = new DirectoryEntry(objectDn);
    strValue = ent.Properties[attributeName].Value.ToString();
    ent.Close();
    ent.Dispose();
    return strValue;
}
}


The error occurs at line with code:
strValue = ent.Properties[attributeName].Value.ToString();


Below is the content error:
COMException was Unhandled by user code
Unspecified error


I was looking for problems like me, but I didn't found good solution.

I try using code in DirectoryEntry:
DirectoryEntry ent = new DirectoryEntry(objectDn,"Administrator","Pass",AuthenticationTypes.Secure);

and also tried disabling firewall and nothing has helped.
Posted
Updated 2-Mar-11 12:46pm
v2
Comments
HimanshuJoshi 2-Mar-11 18:47pm    
Edited to add pre blocks around code.

1 solution

Try this

ent.Properties[attributeName][0].ToString();
 
Share this answer
 
Comments
Dylan Morley 3-Mar-11 5:56am    
Comment from OP: No, it doesn't work.
luisnike19 3-Mar-11 15:18pm    
same error?
luisnike19 3-Mar-11 15:18pm    
just in case, did you check the event viewer?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900