473,796 Members | 2,483 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Q: searching active directory

Hello,
Here is my code that I got from internet and I am assuming this give me
e-mail address of the people in the active directory.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
Dim rootEntry As New DirectoryEntry( "GC://dc=oecc,dc=net" )
Dim searcher As New DirectorySearch er(rootEntry)
searcher.Proper tiesToLoad.Add( "mail")

Dim results As SearchResultCol lection
results = searcher.FindAl l()

Dim result As SearchResult

For Each result In results
Response.Write( result.Properti es("mail")(0))
Next

End Sub

I got “Object reference not set to an instance of an object” at line
Response.Write( result.Properti es("mail")(0)) , what am I missing?
Thanks,
Jim.

Nov 19 '05
12 1560
Juan,
I use this at the filter
searcher.Filter = "(&(anr=myUser) (objectCategory =person))"
and this to see the result,
Response.Write( result.Properti es("mail")(0))
It seems I am getting active directory E-mail information for myUser.
Problem is when user does not have anything defined in the e-mail field,
response.write fails. How should I prevent from that?
Thanks,
Jim.
"JIM.H." wrote:
Juan,
Thanks for your help. your are very helpful. when I did,
searcher.Filter = "(&(anr=myUser) (objectCategory =mail))"
this did not give anything. I am using
Response.Write( result.GetDirec toryEntry.Name) to display result, is this
correct?
"Juan T. Llibre" wrote:
You'd need to modify the Filter.

searcher.Filter = "(&(anr=myUser) (objectCategory =person))"

Changing the objectCategory to the
category for "mail" should do it.

See a complete listing for LDAP objectCategorie s at:
http://dotnetjunkies.com/WebLog/bria.../31/40012.aspx


Juan T. Llibre
ASP.NET MVP
===========
"JIM.H." <JI**@discussio ns.microsoft.co m> wrote in message
news:D5******** *************** ***********@mic rosoft.com...
Thanks Juan,
It hellped well. I still have a problem though. This code gives me the
display name from active directory for myUser, I was trying to achive
e-mail
of the user, how should I get it?
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
Dim rootEntry As New DirectoryEntry( "LDAP://DC=MYDOMAIN,DC= net",
"MYDOMAIN\Admin ", "myPassword ")

Dim searcher As New DirectorySearch er(rootEntry)
searcher.Proper tiesToLoad.Add( "cn")
searcher.Proper tiesToLoad.Add( "mail")

searcher.Filter = "(&(anr=myUser) (objectCategory =person))"

Dim results As SearchResultCol lection
results = searcher.FindAl l()

Dim result As SearchResult

For Each result In results
Response.Write( result.GetDirec toryEntry.Name)
Next

End Sub
Thanks,
Jim.
"Juan T. Llibre" wrote:

> The server which is managing the
> Active Directory you want to search.
>
> You'll also need to feed the name and password
> of a user authorized to access the LDAP server.
>
> C#
> DirectoryEntry rootentry = new DirectoryEntry( LDAP://ADservername,
> "username","pas sword");
>
> VB.NET
> Dim rootEntry As New DirectoryEntry( LDAP://ADservername,
> "username","pas sword")
>
> See:
> http://www.codeproject.com/aspnet/ac...rectoryuse.asp
>
>
>
>
>
> Juan T. Llibre
> ASP.NET MVP
> ===========
> "JIM.H." <JI**@discussio ns.microsoft.co m> wrote in message
> news:66******** *************** ***********@mic rosoft.com...
> > yes but it requires a server name, which server I need to give?
> >
> > "David Jessee" wrote:
> >
> >> Shouldn't your DirectoryEntry Constructor start with LDAP:// ?
> >>
> >> "JIM.H." <JI**@discussio ns.microsoft.co m> wrote in message
> >> news:61******** *************** ***********@mic rosoft.com...
> >> > Hello,
> >> > Here is my code that I got from internet and I am assuming this give
> >> > me
> >> > e-mail address of the people in the active directory.
> >> >
> >> > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> >> > System.EventArg s) Handles MyBase.Load
> >> > 'Put user code to initialize the page here
> >> > Dim rootEntry As New DirectoryEntry( "GC://dc=oecc,dc=net" )
> >> > Dim searcher As New DirectorySearch er(rootEntry)
> >> > searcher.Proper tiesToLoad.Add( "mail")
> >> >
> >> > Dim results As SearchResultCol lection
> >> > results = searcher.FindAl l()
> >> >
> >> > Dim result As SearchResult
> >> >
> >> > For Each result In results
> >> > Response.Write( result.Properti es("mail")(0))
> >> > Next
> >> >
> >> > End Sub
> >> >
> >> > I got "Object reference not set to an instance of an object" at line
> >> > Response.Write( result.Properti es("mail")(0)) , what am I missing?
> >> > Thanks,
> >> > Jim.
> >> >
> >> >
> >> >
> >>
> >>
> >>
>
>
>


Nov 19 '05 #11
Try

Response.Write( Result.GetDirec toryEntry().Pro perties("mail") .Value)

C'ya tomorrow! I'm outtahere.

Going to see a movie ( need to blow off some steam )


Juan T. Llibre
ASP.NET MVP
===========
"JIM.H." <JI**@discussio ns.microsoft.co m> wrote in message
news:76******** *************** ***********@mic rosoft.com...
Juan,
Thanks for your help. your are very helpful. when I did,
searcher.Filter = "(&(anr=myUser) (objectCategory =mail))"
this did not give anything. I am using
Response.Write( result.GetDirec toryEntry.Name) to display result, is this
correct?
"Juan T. Llibre" wrote:
You'd need to modify the Filter.

searcher.Filter = "(&(anr=myUser) (objectCategory =person))"

Changing the objectCategory to the
category for "mail" should do it.

See a complete listing for LDAP objectCategorie s at:
http://dotnetjunkies.com/WebLog/bria.../31/40012.aspx


Juan T. Llibre
ASP.NET MVP
===========
"JIM.H." <JI**@discussio ns.microsoft.co m> wrote in message
news:D5******** *************** ***********@mic rosoft.com...
> Thanks Juan,
> It hellped well. I still have a problem though. This code gives me the
> display name from active directory for myUser, I was trying to achive
> e-mail
> of the user, how should I get it?
>
>
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArg s) Handles MyBase.Load
> 'Put user code to initialize the page here
> Dim rootEntry As New DirectoryEntry( "LDAP://DC=MYDOMAIN,DC= net",
> "MYDOMAIN\Admin ", "myPassword ")
>
> Dim searcher As New DirectorySearch er(rootEntry)
> searcher.Proper tiesToLoad.Add( "cn")
> searcher.Proper tiesToLoad.Add( "mail")
>
> searcher.Filter = "(&(anr=myUser) (objectCategory =person))"
>
> Dim results As SearchResultCol lection
> results = searcher.FindAl l()
>
> Dim result As SearchResult
>
> For Each result In results
> Response.Write( result.GetDirec toryEntry.Name)
> Next
>
> End Sub
> Thanks,
> Jim.
>
>
> "Juan T. Llibre" wrote:
>
>> The server which is managing the
>> Active Directory you want to search.
>>
>> You'll also need to feed the name and password
>> of a user authorized to access the LDAP server.
>>
>> C#
>> DirectoryEntry rootentry = new DirectoryEntry( LDAP://ADservername,
>> "username","pas sword");
>>
>> VB.NET
>> Dim rootEntry As New DirectoryEntry( LDAP://ADservername,
>> "username","pas sword")
>>
>> See:
>> http://www.codeproject.com/aspnet/ac...rectoryuse.asp
>>
>>
>>
>>
>>
>> Juan T. Llibre
>> ASP.NET MVP
>> ===========
>> "JIM.H." <JI**@discussio ns.microsoft.co m> wrote in message
>> news:66******** *************** ***********@mic rosoft.com...
>> > yes but it requires a server name, which server I need to give?
>> >
>> > "David Jessee" wrote:
>> >
>> >> Shouldn't your DirectoryEntry Constructor start with LDAP:// ?
>> >>
>> >> "JIM.H." <JI**@discussio ns.microsoft.co m> wrote in message
>> >> news:61******** *************** ***********@mic rosoft.com...
>> >> > Hello,
>> >> > Here is my code that I got from internet and I am assuming this
>> >> > give
>> >> > me
>> >> > e-mail address of the people in the active directory.
>> >> >
>> >> > Private Sub Page_Load(ByVal sender As System.Object, ByVal e
>> >> > As
>> >> > System.EventArg s) Handles MyBase.Load
>> >> > 'Put user code to initialize the page here
>> >> > Dim rootEntry As New
>> >> > DirectoryEntry( "GC://dc=oecc,dc=net" )
>> >> > Dim searcher As New DirectorySearch er(rootEntry)
>> >> > searcher.Proper tiesToLoad.Add( "mail")
>> >> >
>> >> > Dim results As SearchResultCol lection
>> >> > results = searcher.FindAl l()
>> >> >
>> >> > Dim result As SearchResult
>> >> >
>> >> > For Each result In results
>> >> > Response.Write( result.Properti es("mail")(0))
>> >> > Next
>> >> >
>> >> > End Sub
>> >> >
>> >> > I got "Object reference not set to an instance of an object" at
>> >> > line
>> >> > Response.Write( result.Properti es("mail")(0)) , what am I missing?
>> >> > Thanks,
>> >> > Jim.
>> >> >
>> >> >
>> >> >
>> >>
>> >>
>> >>
>>
>>
>>


Nov 19 '05 #12
OK...

You should check for null values,
and replace the null value with a space " ".

Sorry, I don't have time for real code right now.

pseudo code :

If IsNull(result.P roperties("mail ")(0)) Then
result.Properti es("mail")(0) = " "
else
Response.Write( result.Properti es("mail")(0))
End if

You might have to do some syntax-checking.
I'm on the run to the movies...


Juan T. Llibre
ASP.NET MVP
===========
"JIM.H." <JI**@discussio ns.microsoft.co m> wrote in message
news:2C******** *************** ***********@mic rosoft.com...
Juan,
I use this at the filter
searcher.Filter = "(&(anr=myUser) (objectCategory =person))"
and this to see the result,
Response.Write( result.Properti es("mail")(0))
It seems I am getting active directory E-mail information for myUser.
Problem is when user does not have anything defined in the e-mail field,
response.write fails. How should I prevent from that?
Thanks,
Jim.
"JIM.H." wrote:
Juan,
Thanks for your help. your are very helpful. when I did,
searcher.Filter = "(&(anr=myUser) (objectCategory =mail))"
this did not give anything. I am using
Response.Write( result.GetDirec toryEntry.Name) to display result, is this
correct?
"Juan T. Llibre" wrote:
> You'd need to modify the Filter.
>
> searcher.Filter = "(&(anr=myUser) (objectCategory =person))"
>
> Changing the objectCategory to the
> category for "mail" should do it.
>
> See a complete listing for LDAP objectCategorie s at:
> http://dotnetjunkies.com/WebLog/bria.../31/40012.aspx
>
>
>
>
> Juan T. Llibre
> ASP.NET MVP
> ===========
> "JIM.H." <JI**@discussio ns.microsoft.co m> wrote in message
> news:D5******** *************** ***********@mic rosoft.com...
> > Thanks Juan,
> > It hellped well. I still have a problem though. This code gives me
> > the
> > display name from active directory for myUser, I was trying to achive
> > e-mail
> > of the user, how should I get it?
> >
> >
> > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> > System.EventArg s) Handles MyBase.Load
> > 'Put user code to initialize the page here
> > Dim rootEntry As New
> > DirectoryEntry( "LDAP://DC=MYDOMAIN,DC= net",
> > "MYDOMAIN\Admin ", "myPassword ")
> >
> > Dim searcher As New DirectorySearch er(rootEntry)
> > searcher.Proper tiesToLoad.Add( "cn")
> > searcher.Proper tiesToLoad.Add( "mail")
> >
> > searcher.Filter = "(&(anr=myUser) (objectCategory =person))"
> >
> > Dim results As SearchResultCol lection
> > results = searcher.FindAl l()
> >
> > Dim result As SearchResult
> >
> > For Each result In results
> > Response.Write( result.GetDirec toryEntry.Name)
> > Next
> >
> > End Sub
> > Thanks,
> > Jim.
> >
> >
> > "Juan T. Llibre" wrote:
> >
> >> The server which is managing the
> >> Active Directory you want to search.
> >>
> >> You'll also need to feed the name and password
> >> of a user authorized to access the LDAP server.
> >>
> >> C#
> >> DirectoryEntry rootentry = new DirectoryEntry( LDAP://ADservername,
> >> "username","pas sword");
> >>
> >> VB.NET
> >> Dim rootEntry As New DirectoryEntry( LDAP://ADservername,
> >> "username","pas sword")
> >>
> >> See:
> >> http://www.codeproject.com/aspnet/ac...rectoryuse.asp
> >>
> >>
> >>
> >>
> >>
> >> Juan T. Llibre
> >> ASP.NET MVP
> >> ===========
> >> "JIM.H." <JI**@discussio ns.microsoft.co m> wrote in message
> >> news:66******** *************** ***********@mic rosoft.com...
> >> > yes but it requires a server name, which server I need to give?
> >> >
> >> > "David Jessee" wrote:
> >> >
> >> >> Shouldn't your DirectoryEntry Constructor start with LDAP:// ?
> >> >>
> >> >> "JIM.H." <JI**@discussio ns.microsoft.co m> wrote in message
> >> >> news:61******** *************** ***********@mic rosoft.com...
> >> >> > Hello,
> >> >> > Here is my code that I got from internet and I am assuming this
> >> >> > give
> >> >> > me
> >> >> > e-mail address of the people in the active directory.
> >> >> >
> >> >> > Private Sub Page_Load(ByVal sender As System.Object, ByVal e
> >> >> > As
> >> >> > System.EventArg s) Handles MyBase.Load
> >> >> > 'Put user code to initialize the page here
> >> >> > Dim rootEntry As New
> >> >> > DirectoryEntry( "GC://dc=oecc,dc=net" )
> >> >> > Dim searcher As New DirectorySearch er(rootEntry)
> >> >> > searcher.Proper tiesToLoad.Add( "mail")
> >> >> >
> >> >> > Dim results As SearchResultCol lection
> >> >> > results = searcher.FindAl l()
> >> >> >
> >> >> > Dim result As SearchResult
> >> >> >
> >> >> > For Each result In results
> >> >> > Response.Write( result.Properti es("mail")(0))
> >> >> > Next
> >> >> >
> >> >> > End Sub
> >> >> >
> >> >> > I got "Object reference not set to an instance of an object" at
> >> >> > line
> >> >> > Response.Write( result.Properti es("mail")(0)) , what am I
> >> >> > missing?
> >> >> > Thanks,
> >> >> > Jim.
> >> >> >
> >> >> >
> >> >> >
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>

Nov 19 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1667
by: scoomey | last post by:
Note: I'm cross-posting the below to nyphp.org as well. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I've been struggling with an issue for a few months. I am attempting to search Active Directory 2003 via PHP, but am running into an issue searching from the base DN (i.e. 'cn=company,cn=com'). This seems to be somewhat of a known issue with AD2K3. A search at this level always returns:
2
15193
by: James Allan | last post by:
Hello -- I'm trying to get SQL Server 2000 on a Windows 2000 Server to be able to query an Active Directory. We've got two domain servers one Win2000 and one Win2003. However, I'm having problems: I've run the following query to setup the linked server: sp_addlinkedserver 'ADSI', 'Active Directory Service Interfaces', 'ADSDSOObject', 'adsdatasource'
4
7133
by: Brandon Arnold | last post by:
Hello All, I have a linked ADSI Server to our company Active Directory and everything is fine. I'm running queries and such using LDAP. BUT how can I aquire a list of attributes for the classes and categories. Such as if i wanted to see a user's telephone number and email address for use in a corporate database? Is this possible? Thanks
0
3740
by: Mario Rodriguez | last post by:
Hi I am trying to search activeDirectory through OLEDB and I am getting the exception like this DB_E_NOTABLE(0x80040E37) at OleDbDataAdapter.Fill method. My code look like this. OleDbConnection activeConn = new OleDbConnection("Provider=ADSDSOObject"); string cmdString = "SELECT * FROM 'LDAP://DC=domain name, DC=COM' WHERE objectClass='OU'"; OleDbDataAdapter custDA = new OleDbDataAdapter(); DataSet dataset = new DataSet();...
5
5811
by: Bud | last post by:
I would like to be able to pass a request to IIS to have a user name and password authenticated against my Active Directory Users database. I'm running Server 2003 however my web pages are build using ASP (not .NET). What I want to do is to open the standard User Name/Password form (I don't know how to do that either) and then make my request and get back a True/False result. There must be a way to do that but I haven't found it after 3...
1
7315
by: anonymous | last post by:
Hi all, I've been searching the way to achieve the following task. But no luck so far. I have a web site(main site), which requires authentication. This authentication is set at Windows directory level, so user will see the pop up gray box in order to log in rather than custom web page. The username and password are stored at active directory level, thus this is the windows integrated security.
0
1564
by: Federica | last post by:
Hi! I need some help retrieving user information in Active Directory. I have one webform with 2 textboxes 1 username and one for password. When the user load this page and insert his username and password (the same that he use for the login on the Windows Domain - is a requirement!) he click the button login. At this point I need to connect to Active Directory searching if this username and this password are valid for this domain and I...
1
3895
by: tangus via DotNetMonster.com | last post by:
Hello all, I'm really struggling with getting some Active Directory code to work in ASP.NET. Can you please provide assistance? I am executing the following code: Dim enTry As DirectoryEntry = New DirectoryEntry("LDAP://domain") Dim mySearcher As New DirectorySearcher(enTry) Dim resEnt As SearchResult mySearcher.Filter = ("(objectClass=*)") mySearcher.SearchScope = SearchScope.Subtree
2
1432
Daxthecon
by: Daxthecon | last post by:
The web application I am developing is using Active Directory and seeing as how I have never used the namespace before in C# or VB.NET I would like someone to point me to a great site(I have not found what I need on MSDN nor Google). I must be looking for the wrong things. I am trying to write permissions for tables on a GridView and still need help writing to a SQL DB and can't find any code references to go off of. As some of you know I was...
0
9528
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10173
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10006
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7547
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6788
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5441
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4116
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.