Question : Need help with DirectoryServices namespace in c#

Hello, I am getting a compilation error on my System.DirectoryServices namespace:

"Error      1      The type or namespace name 'DirectoryServices' does not exist in the namespace 'System' (are you missing an assembly reference?"

How do I install this assembly?

Thank you
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.DirectoryServices;
 
namespace LDAP
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter user: ");
            String username = Console.ReadLine();
 
            try
            {
                // create LDAP connection object
 
                DirectoryEntry myLdapConnection = createDirectoryEntry();
 
                // create search object which operates on LDAP connection object
                // and set search object to only find the user specified
 
                DirectorySearcher search = new DirectorySearcher(myLdapConnection);
                search.Filter = "(cn=" + username + ")";
 
                // create results objects from search object
 
                SearchResult result = search.FindOne();
 
                if (result != null)
                {
                    // user exists, cycle through LDAP fields (cn, telephonenumber etc.)
 
                    ResultPropertyCollection fields = result.Properties;
 
                    foreach (String ldapField in fields.PropertyNames)
                    {
                        // cycle through objects in each field e.g. group membership
                        // (for many fields there will only be one object such as name)
 
                        foreach (Object myCollection in fields[ldapField])
                            Console.WriteLine(String.Format("{0,-20} : {1}",
                                          ldapField, myCollection.ToString()));
                    }
                }
 
                else
                {
                    // user does not exist
                    Console.WriteLine("User not found!");
                }
            }
 
            catch (Exception e)
            {
                Console.WriteLine("Exception caught:\n\n" + e.ToString());
            }
        }
 
        static DirectoryEntry createDirectoryEntry()
        {
            // create and return new LDAP connection with desired settings
 
            DirectoryEntry ldapConnection = new DirectoryEntry("my.domain");
            ldapConnection.Path = "LDAP://OU=myou,DC=mydc,DC=mydc,DC=mydc";
            ldapConnection.AuthenticationType = AuthenticationTypes.Secure;
 
            return ldapConnection;
        }
    }
}
Open in New Window Select All

Answer : Need help with DirectoryServices namespace in c#

step-by-step
 
step 1
step 1
 
 
step 2
step 2
 
Random Solutions  
 
programming4us programming4us