|
Happy New Year Everyone!
Please help I am writing a code that searches the Active directory, it first get the list of properties, then use each property name to get its value. I filter the directory searcher by the cn. My problem is that for some people the search doesn't return the "mail" property, this is the property I need most. Please find my code snippet below.
DirectoryEntry de = new DirectoryEntry("LDAP://" + "AFLIFEDC04",
@"aflife\alsql", "perseus", AuthenticationTypes.FastBind);
string[] propertiesFound;
string Email = "";
DirectorySearcher ds = new DirectorySearcher(de);
//Use the users full name to get the email address from directory services
ds.Filter = "(cn=" + FullName + ")";
ds.SearchScope = SearchScope.Subtree;
try
{
SearchResultCollection results = ds.FindAll();
foreach (SearchResult result in results)
{
int a = 0;
ResultPropertyCollection propc = result.Properties;
DirectoryEntry dey = result.GetDirectoryEntry();
propertiesFound = new string[propc.Count];
// Loading all the properties return into the propertieFound array
foreach (string propertyName in propc.PropertyNames)
{
//This where the problem is, for some I get like 38 properties,
//for others I get 34. What is the cause of and what is the
//solution to it.
propertiesFound[a] = propertyName;
a++;
}
}
}
Thank you in advanced for your solutions.
Kind Regards
Mpumelelo Khuzwayo
khuzym
|
|
|
|
|
I ran into this problem a while back, but I don't remember what the problem was, and why you can't return the E-Mail property the way you do other properties. Anyway, here is the code I came up with the return the E-Mail property.
public static string getUserEMail(string fullname)
{
string email = string.Empty;
DirectorySearcher search = new DirectorySearcher();
search.Filter = "(cn=" + fullname + ")";
search.PropertiesToLoad.Add("mail");
try
{
SearchResult result = search.FindOne();
if (null != result)
{
email = (String)result.Properties["mail"][0];
return email;
}
else
{
return "Could not find Email address!";
}
}
catch (Exception ex)
{
return ex.Message;
}
}
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
Good Morning Justin
Thank you for your reply, I have tried implementing it, the problem it returns the adspath property and not mail property. I don't know if you hav an idea what is the cause.
Thank you again.
I will keep on trying different things, I have a feeling the problem is very small!
khuzym
|
|
|
|
|
i want to use excel file values in my c# code,how can i get that??????
|
|
|
|
|
Member 4756709 wrote: i want to use excel file values in my c# code,how can i get that??????
Give a little more detail. What is it that you are wanting to do? What have you tried?
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
Hello,
How can i get IP addess of the computers connected with LAN?
Thank you
Dipak
|
|
|
|
|
and u're acting as a Client/Server
have u tried tcpcliecnt?
more inforamatio will help us to help u
Where there is a will
there is a way (yeh, right, hahaha)
|
|
|
|
|
Thank you for Reply
Yes i am as a client of that LAN. And i want to get all the IP Addresses and Names of the computers connected with the same LAN.
I have tried this way for test:
using System.Net;
String strHostName = Dns.GetHostName();
MessageBox.Show(strHostName.ToString());
IPHostEntry ipEntry = Dns.GetHostByName(strHostName);
IPAddress[] addr = ipEntry.AddressList;
for (int i = 0; i < addr.Length; i++)
{
MessageBox.Show(addr[i].ToString());
}
But it gets only My Computer's IP Address and another one IP address. I think it is mac address. I have put that IP Address on Run "\\121.245.75.159" but i opens my ShareDocs.
Please help me.
Dipak
|
|
|
|
|
Just an idea, but what if you get your own ip address (using the method you described), your own subnet mask[^], and then ping all the possible addresses within that subnet? The link (labeled "subnet mask" will also allow you to ping the other addresses as well). This will work assuming your subnet mask limits the number of possible ip's to a reasonable number (probably less than 2^8 is reasonable.) Hopefully someone else will offer a more efficient way to do this for you, but in the meantime this will work.
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
You'll have to go through the entire range of IP addresses, PING each one to see if it responds, and if so, resolve that IP to its host name. There is no one function that you can call to give you the entire list.
|
|
|
|
|
hi
i want to add a eventhandler for a mshtml.ihtmlelement.could any one help me to do this please.
with regards
Balagurunathan.B
|
|
|
|
|
|
i am not getting wat you r trying to say
i just asked how to handle the events of mshtml.ihtmlelement using c#. i dint asked abt that msdn post
with regards
Balagurunathan.B
|
|
|
|
|
|
You should connect to SQL database[ADO.net] and use sql commands to make the changes on the database.
Check out this sample[^]
|
|
|
|
|
dear Manoj;
i'm using c# windows form not webform
|
|
|
|
|
Hi All,
Is there a way to Convert a string "Yes" to Boolean - or does this apply only to True/False, 1/0.
I've had a look at Parse, Convert.ToBoolean , and BooleanConverter , but no joy.
Thanks
J
|
|
|
|
|
string myString = "Yes";<br />
bool myBool = (myString == "Yes") ? true : false;
There is no automagic, built-in way, no.
|
|
|
|
|
if(val.ToLower()=="yes")
valConvert=True
else
valConvert=False
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
hmmmm..
OK, thanks Chaps.
J
|
|
|
|
|
Rather than using val.ToLower(), why not use string.Compare with the appropriate case sensitivity test in there?
if (string.Compare(val, "yes", true) == 0)
|
|
|
|
|
no if, no ternary operator:
valConvert=val.ToLower()=="yes";
|
|
|
|
|
Yes is a string, and cannot be converted directly to boolean - as it's specific to the English language. If you were to allow this to be translated, then you'd have to take case and culture into account, e.g. Ja, ja, JA, Oui, OUI, oui.
|
|
|
|
|
|
One more thing..
bool boo = Convert.ToBoolean("True");
boo returns as True .
If my Culture was "fr-FR ", and :
bool boo = Convert.ToBoolean("Vrai");
would boo return as True/Vrai ?
Thanks
J
|
|
|
|