please delete thread....
-
I did a little more testing for you. The reason the result is null is because AD does not contain an entry for the userName provided. Try using a different username for the userName variable. Confirmed here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sds/sds/directoryservices_directorysearcher_findone.asp[^] If more than one entry is found during the search, only the first entry is returned. If no entries are found to match the search criteria, a null reference (Nothing in Visual Basic) is returned.
Just because we can; does not mean we should.
-
After 3 hours of frustration I need some help with the findOne() method. FindAll() is no problem but after gong through and trying findOne() code I have only gotten one to work all the others fail (including the one on this site: http://www.codeproject.com/KB/system/QueryADwithDotNet.aspx[^]. The problem seems to be with the search filter, I have to set it to "samaccountname":
DirectorySearcher search = new DirectorySearcher(); //this filter works search.Filter = "samaccountname=" + userName; //This below formats for the search filter result in result=null //search.Filter = String.Format("(cn={0})", userName); //code project filter //search.Filter = "cn=" + userName; search.PropertiesToLoad.Add("memberOf"); StringBuilder groupsList = new StringBuilder(); SearchResult result = search.FindOne(); if (result != null) { int groupCount = result.Properties["memberOf"].Count; for (int counter = 0; counter < groupCount; counter++) { groupsList.Append((string)result.Properties["memberOf"][counter]); groupsList.Append("|"); } } else { MessageBox.Show("not found"); }
help!!! shwaguymodified on Friday, December 28, 2007 12:37:58 PM
It is proper to keep a thread even if you already found the solution. Someone later on might have the same type of problem and this thread could help them.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
-
It is proper to keep a thread even if you already found the solution. Someone later on might have the same type of problem and this thread could help them.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
Hi Paul, I agree. In this case no solution was found for the original question and the thread turned into an unreadable mess that would only serve to waste the time of someone seeking a solution. Usually, I get good or great responses from this forum. People usually read, think then answer (even if the correct solution is not given). Maybe I just asked on a bad day. shwaguy
-
Hi Paul, I agree. In this case no solution was found for the original question and the thread turned into an unreadable mess that would only serve to waste the time of someone seeking a solution. Usually, I get good or great responses from this forum. People usually read, think then answer (even if the correct solution is not given). Maybe I just asked on a bad day. shwaguy
shwaguy wrote:
Maybe I just asked on a bad day.
Or, more likely, you asked a poorly defined question and are now upset and pouting. :((
only two letters away from being an asset
-
shwaguy wrote:
so I will ask later.
I'll remember to ignore you then.
only two letters away from being an asset
thanks for letting me know you will ignore my threads...it was very useful on topic information (sc). I understand that people make mistakes, but, when I get 3 knee jerk responses (responses that have NO input to the question) in a row I tend to figure noone will want to read the thread. I twice stated that there was no issue with the existing code, but, you seemed to miss that. Your ego must be easily bruised if to be hurt by those exclamation marks. -If a response is not the solution thats all good. -If a response is correct solution thats all good. -If the response is off topic becuase the poster did not bother to read the post....I think "I wish that the poster could delete the response, its a waste of reading time and clutters the original post" You take offense way too easily. Just because you have 3500 posts does not mean I am kissing your butt for very poor, of topic, replies. I don't have anything against you either, I think you may have helped a lot of threads. shwaguy
-
shwaguy wrote:
Maybe I just asked on a bad day.
Or, more likely, you asked a poorly defined question and are now upset and pouting. :((
only two letters away from being an asset
-
Hi Paul, I agree. In this case no solution was found for the original question and the thread turned into an unreadable mess that would only serve to waste the time of someone seeking a solution. Usually, I get good or great responses from this forum. People usually read, think then answer (even if the correct solution is not given). Maybe I just asked on a bad day. shwaguy
shwaguy wrote:
the original question
It did sound rather vague.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
-
thanks for letting me know you will ignore my threads...it was very useful on topic information (sc). I understand that people make mistakes, but, when I get 3 knee jerk responses (responses that have NO input to the question) in a row I tend to figure noone will want to read the thread. I twice stated that there was no issue with the existing code, but, you seemed to miss that. Your ego must be easily bruised if to be hurt by those exclamation marks. -If a response is not the solution thats all good. -If a response is correct solution thats all good. -If the response is off topic becuase the poster did not bother to read the post....I think "I wish that the poster could delete the response, its a waste of reading time and clutters the original post" You take offense way too easily. Just because you have 3500 posts does not mean I am kissing your butt for very poor, of topic, replies. I don't have anything against you either, I think you may have helped a lot of threads. shwaguy
:laugh: :laugh: :laugh:
shwaguy wrote:
I twice stated that there was no issue with the existing code,
Then why did you post it? Go away, son, you bore me.
only two letters away from being an asset
-
shwaguy wrote:
the original question
It did sound rather vague.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
Putting aside the 2 replies I got being totally off topic: - "what error message did you get?" - uh...none...I got a null value as stated. - replace code that was stated as working search.Filter = "samaccountname=" + userName; with this other filter that works equally well too (blah, blah, blah). Whats vague about the post?: //this filter works search.Filter = "samaccountname=" + userName; //This below formats for the search filter result in result=null //search.Filter = String.Format("(cn={0})", userName); //code project filter //search.Filter = "cn=" + userName; SearchResult result = search.FindOne(); shwaguy
-
:laugh: :laugh: :laugh:
shwaguy wrote:
I twice stated that there was no issue with the existing code,
Then why did you post it? Go away, son, you bore me.
only two letters away from being an asset
You just have to feel like your right on this don't you? Here is the news, you are wrong again. The code although correct did not suit my purpose. If you bothered to read the posting you would have noted that I commented out (with comments) the items that would not work, but wanted to work. as previously stated: beat it.
-
Putting aside the 2 replies I got being totally off topic: - "what error message did you get?" - uh...none...I got a null value as stated. - replace code that was stated as working search.Filter = "samaccountname=" + userName; with this other filter that works equally well too (blah, blah, blah). Whats vague about the post?: //this filter works search.Filter = "samaccountname=" + userName; //This below formats for the search filter result in result=null //search.Filter = String.Format("(cn={0})", userName); //code project filter //search.Filter = "cn=" + userName; SearchResult result = search.FindOne(); shwaguy
The original post was rather vague. Not the ones that followed.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon