Click here to Skip to main content
15,888,031 members
Home / Discussions / C#
   

C#

 
GeneralRe: Thanks you for your advise. but I can't use this way. Pin
BobJanova24-May-12 0:52
BobJanova24-May-12 0:52 
GeneralRe: Thanks you for your advise. but I can't use this way. Pin
Pete O'Hanlon24-May-12 1:21
mvePete O'Hanlon24-May-12 1:21 
QuestionLooking for help querying active directory Pin
turbosupramk323-May-12 9:08
turbosupramk323-May-12 9:08 
AnswerRe: Looking for help querying active directory Pin
Dave Kreskowiak23-May-12 9:58
mveDave Kreskowiak23-May-12 9:58 
GeneralRe: Looking for help querying active directory Pin
turbosupramk323-May-12 10:23
turbosupramk323-May-12 10:23 
GeneralRe: Looking for help querying active directory Pin
Dave Kreskowiak23-May-12 12:09
mveDave Kreskowiak23-May-12 12:09 
GeneralRe: Looking for help querying active directory Pin
turbosupramk323-May-12 14:29
turbosupramk323-May-12 14:29 
AnswerRe: Looking for help querying active directory Pin
randprin24-May-12 2:16
randprin24-May-12 2:16 
C#
using (var rootDirectory = new DirectoryEntry("LDAP://[Server IP or Host name]", "[user name in the directory]", "[User Password]")) {
           using (var directorySearch = new DirectorySearcher(rootDirectory)) {
              // your filter should be an LDAP Query, the one i put in the sample look a matching name or sAMAccountName
              directorySearch.Filter = string.Format("(|(sAMAccountName={0})(name={0}))", "[User Name you want or account you want]");
              // you can add non standard properties to your query:
              // some samples are "memberOf" for getting all groups the entry you want are related to (1 level up only)
              // or "member" for all members of a group (1 level down only
              directorySearch.PropertiesToLoad.Add("[Name of the property you want, exactly as it appears in the AD]");

              // return an entry if there's a match
              var result = directorySearch.FindOne();

              if (result != null) {
                 // by the search result, get the associated directory entry, as the result object can be complex to work with.
                 var directoryEntry = result.GetDirectoryEntry();

                 // Note that entries contain between 40-60 properties by default, plus whatever properties you asked to load
                 // in the directory search, as long as your domain admin did not restrict access to them
                 // (in which case the root user you used to start this chain need to have permissions to read those properties)
                 var propertyIwant = directoryEntry.Properties["Name of the property you want"];
              }
           }
        }


this should get you started, if you want more then the first item associated with your query, use "FindAll" and then iterate on the results
Edit: totally forgot, remember you need to reference System.DirectoryServices to use this code.
GeneralRe: Looking for help querying active directory Pin
turbosupramk324-May-12 9:33
turbosupramk324-May-12 9:33 
GeneralRe: Looking for help querying active directory Pin
turbosupramk329-May-12 4:35
turbosupramk329-May-12 4:35 
QuestionUsing ADWS in .Net Pin
Member 254690323-May-12 6:40
Member 254690323-May-12 6:40 
AnswerRe: Using ADWS in .Net Pin
Ravi Bhavnani23-May-12 9:33
professionalRavi Bhavnani23-May-12 9:33 
GeneralRe: Using ADWS in .Net Pin
Member 254690323-May-12 9:59
Member 254690323-May-12 9:59 
GeneralSystem.IO Project for beginners Pin
bdeklerk23-May-12 2:28
bdeklerk23-May-12 2:28 
GeneralRe: System.IO Project for beginners Pin
ddecoy23-May-12 3:31
ddecoy23-May-12 3:31 
AnswerRe: System.IO Project for beginners Pin
Eddy Vluggen23-May-12 10:42
professionalEddy Vluggen23-May-12 10:42 
QuestionCrystal reports not working on win 7 - 64bit. help Pin
Waqas Ahmad Abbasi22-May-12 19:38
Waqas Ahmad Abbasi22-May-12 19:38 
AnswerRe: Crystal reports not working on win 7 - 64bit. help Pin
Bernhard Hiller22-May-12 22:10
Bernhard Hiller22-May-12 22:10 
AnswerRe: Crystal reports not working on win 7 - 64bit. help Pin
Sandeep Mewara22-May-12 23:38
mveSandeep Mewara22-May-12 23:38 
QuestionProblem in merging two files -pcl file Pin
shamypnr22-May-12 19:15
shamypnr22-May-12 19:15 
AnswerRe: Problem in merging two files - images Pin
Richard MacCutchan22-May-12 22:43
mveRichard MacCutchan22-May-12 22:43 
Questionsoftware copy protection Pin
Alex Nguyen1222-May-12 12:35
Alex Nguyen1222-May-12 12:35 
AnswerRe: software copy protection Pin
Dave Kreskowiak22-May-12 13:46
mveDave Kreskowiak22-May-12 13:46 
GeneralRe: software copy protection Pin
Bernhard Hiller22-May-12 22:18
Bernhard Hiller22-May-12 22:18 
AnswerRe: software copy protection Pin
Eddy Vluggen23-May-12 0:25
professionalEddy Vluggen23-May-12 0:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.