writing c# code to get info from LDAP

Posted on 2013-06-13
Last Modified: 2013-10-14

I wrote an intranet, and now they want to pull the correct phone numbers for employee's from Active directory via LDAP

I've never used LDAP before, and the Networking department are a pain in the butt to work with, they never help and are always block things

What sort of questions do I need to be asking, or areas to be looking into before starting?
Any advice appreciated to get me upto speed

Question by:websss
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 10

Accepted Solution

Monica P earned 500 total points
ID: 39243923
Refer this link:

Sample Code :

provide your
LDAP_Server_URL ,
ExportAttributes tags

//  *************************************************
//          Setting connection to LDAP Server
//  *************************************************
try {
    q = "";

    cmd = CreateObject("ADODB.Command");
    cn = CreateObject("ADODB.Connection");
    rs = CreateObject("ADODB.Recordset");"Provider=ADsDSOObject;");
    cmd.activeconnection = cn;
    if ((strRoot == "")) {
        objRoot = GetObject(LDAP_Server_URL);
        strRoot = objRoot.GET("defaultNamingContext");
    cmd.commandtext = ("<LDAP://" 
                + (strRoot + (">;" 
                + (strFilter + (";" 
                + (strAttributes + (";" + strScope)))))));["page size"] = 1000;
    rs = cmd.EXECUTE;
catch (Exception ex) {
    Console.WriteLine("Error in setting Active Directory Connection and Command....Press any key to quit");

Open in new window

rs will contain all tags as you set in "strAttributes "...put that into datatable and read them one by one

Expert Comment

ID: 39243964
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 39244346

Author Comment

ID: 39262098
I've tried following this code

But System.directoryServices isn't valid (unknown namespace)

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question