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.EventArgs) 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 DirectorySearcher(rootEntry)
searcher.PropertiesToLoad.Add("mail")
Dim results As SearchResultCollection
results = searcher.FindAll()
Dim result As SearchResult
For Each result In results
Response.Write(result.Properties("mail")(0))
Next
End Sub
I got “Object reference not set to an instance of an object” at line
Response.Write(result.Properties("mail")(0)), what am I missing?
Thanks,
Jim. 12 1538
Hi, Jim.
Have you had a look at : http://msdn.microsoft.com/library/de...etadsearch.asp
?
Juan T. Llibre
ASP.NET MVP
===========
"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:61**********************************@microsof t.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.EventArgs) 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 DirectorySearcher(rootEntry) searcher.PropertiesToLoad.Add("mail")
Dim results As SearchResultCollection results = searcher.FindAll()
Dim result As SearchResult
For Each result In results Response.Write(result.Properties("mail")(0)) Next
End Sub
I got "Object reference not set to an instance of an object" at line Response.Write(result.Properties("mail")(0)), what am I missing? Thanks, Jim.
I whci somebody could tell me what I am missing, I got the code from that
site but not workign for me.
"Juan T. Llibre" wrote: Hi, Jim.
Have you had a look at :
http://msdn.microsoft.com/library/de...etadsearch.asp
?
Juan T. Llibre ASP.NET MVP =========== "JIM.H." <JI**@discussions.microsoft.com> wrote in message news:61**********************************@microsof t.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.EventArgs) 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 DirectorySearcher(rootEntry) searcher.PropertiesToLoad.Add("mail")
Dim results As SearchResultCollection results = searcher.FindAll()
Dim result As SearchResult
For Each result In results Response.Write(result.Properties("mail")(0)) Next
End Sub
I got "Object reference not set to an instance of an object" at line Response.Write(result.Properties("mail")(0)), what am I missing? Thanks, Jim.
Shouldn't your DirectoryEntry Constructor start with LDAP:// ?
"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:61**********************************@microsof t.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.EventArgs) 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 DirectorySearcher(rootEntry) searcher.PropertiesToLoad.Add("mail")
Dim results As SearchResultCollection results = searcher.FindAll()
Dim result As SearchResult
For Each result In results Response.Write(result.Properties("mail")(0)) Next
End Sub
I got "Object reference not set to an instance of an object" at line Response.Write(result.Properties("mail")(0)), what am I missing? Thanks, Jim.
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**@discussions.microsoft.com> wrote in message news:61**********************************@microsof t.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.EventArgs) 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 DirectorySearcher(rootEntry) searcher.PropertiesToLoad.Add("mail")
Dim results As SearchResultCollection results = searcher.FindAll()
Dim result As SearchResult
For Each result In results Response.Write(result.Properties("mail")(0)) Next
End Sub
I got "Object reference not set to an instance of an object" at line Response.Write(result.Properties("mail")(0)), what am I missing? Thanks, Jim.
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","password");
VB.NET
Dim rootEntry As New DirectoryEntry(LDAP://ADservername,
"username","password")
See: http://www.codeproject.com/aspnet/ac...rectoryuse.asp
Juan T. Llibre
ASP.NET MVP
===========
"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:66**********************************@microsof t.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**@discussions.microsoft.com> wrote in message news:61**********************************@microsof t.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.EventArgs) 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 DirectorySearcher(rootEntry) > searcher.PropertiesToLoad.Add("mail") > > Dim results As SearchResultCollection > results = searcher.FindAll() > > Dim result As SearchResult > > For Each result In results > Response.Write(result.Properties("mail")(0)) > Next > > End Sub > > I got "Object reference not set to an instance of an object" at line > Response.Write(result.Properties("mail")(0)), what am I missing? > Thanks, > Jim. > > >
Your LDAP path should look like this :
LDAP://corp.bedking.com/CN=Users,DC=corp,DC=bedking,DC=com
Juan T. Llibre
ASP.NET MVP
===========
"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:%2******************@TK2MSFTNGP15.phx.gbl... 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","password");
VB.NET Dim rootEntry As New DirectoryEntry(LDAP://ADservername, "username","password")
See: http://www.codeproject.com/aspnet/ac...rectoryuse.asp
Juan T. Llibre ASP.NET MVP =========== "JIM.H." <JI**@discussions.microsoft.com> wrote in message news:66**********************************@microsof t.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**@discussions.microsoft.com> wrote in message news:61**********************************@microsof t.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.EventArgs) 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 DirectorySearcher(rootEntry) > searcher.PropertiesToLoad.Add("mail") > > Dim results As SearchResultCollection > results = searcher.FindAll() > > Dim result As SearchResult > > For Each result In results > Response.Write(result.Properties("mail")(0)) > Next > > End Sub > > I got "Object reference not set to an instance of an object" at line > Response.Write(result.Properties("mail")(0)), what am I missing? > Thanks, > Jim. > > >
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.EventArgs) 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 DirectorySearcher(rootEntry)
searcher.PropertiesToLoad.Add("cn")
searcher.PropertiesToLoad.Add("mail")
searcher.Filter = "(&(anr=myUser)(objectCategory=person))"
Dim results As SearchResultCollection
results = searcher.FindAll()
Dim result As SearchResult
For Each result In results
Response.Write(result.GetDirectoryEntry.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","password");
VB.NET Dim rootEntry As New DirectoryEntry(LDAP://ADservername, "username","password")
See: http://www.codeproject.com/aspnet/ac...rectoryuse.asp
Juan T. Llibre ASP.NET MVP =========== "JIM.H." <JI**@discussions.microsoft.com> wrote in message news:66**********************************@microsof t.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**@discussions.microsoft.com> wrote in message news:61**********************************@microsof t.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.EventArgs) 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 DirectorySearcher(rootEntry) > searcher.PropertiesToLoad.Add("mail") > > Dim results As SearchResultCollection > results = searcher.FindAll() > > Dim result As SearchResult > > For Each result In results > Response.Write(result.Properties("mail")(0)) > Next > > End Sub > > I got "Object reference not set to an instance of an object" at line > Response.Write(result.Properties("mail")(0)), what am I missing? > Thanks, > Jim. > > >
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 objectCategories at: http://dotnetjunkies.com/WebLog/bria.../31/40012.aspx
Juan T. Llibre
ASP.NET MVP
===========
"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:D5**********************************@microsof t.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.EventArgs) 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 DirectorySearcher(rootEntry) searcher.PropertiesToLoad.Add("cn") searcher.PropertiesToLoad.Add("mail")
searcher.Filter = "(&(anr=myUser)(objectCategory=person))"
Dim results As SearchResultCollection results = searcher.FindAll()
Dim result As SearchResult
For Each result In results Response.Write(result.GetDirectoryEntry.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","password");
VB.NET Dim rootEntry As New DirectoryEntry(LDAP://ADservername, "username","password")
See: http://www.codeproject.com/aspnet/ac...rectoryuse.asp
Juan T. Llibre ASP.NET MVP =========== "JIM.H." <JI**@discussions.microsoft.com> wrote in message news:66**********************************@microsof t.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**@discussions.microsoft.com> wrote in message >> news:61**********************************@microsof t.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.EventArgs) 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 DirectorySearcher(rootEntry) >> > searcher.PropertiesToLoad.Add("mail") >> > >> > Dim results As SearchResultCollection >> > results = searcher.FindAll() >> > >> > Dim result As SearchResult >> > >> > For Each result In results >> > Response.Write(result.Properties("mail")(0)) >> > Next >> > >> > End Sub >> > >> > I got "Object reference not set to an instance of an object" at line >> > Response.Write(result.Properties("mail")(0)), what am I missing? >> > Thanks, >> > Jim. >> > >> > >> > >> >> >>
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.GetDirectoryEntry.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 objectCategories at: http://dotnetjunkies.com/WebLog/bria.../31/40012.aspx
Juan T. Llibre ASP.NET MVP =========== "JIM.H." <JI**@discussions.microsoft.com> wrote in message news:D5**********************************@microsof t.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.EventArgs) 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 DirectorySearcher(rootEntry) searcher.PropertiesToLoad.Add("cn") searcher.PropertiesToLoad.Add("mail")
searcher.Filter = "(&(anr=myUser)(objectCategory=person))"
Dim results As SearchResultCollection results = searcher.FindAll()
Dim result As SearchResult
For Each result In results Response.Write(result.GetDirectoryEntry.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","password");
VB.NET Dim rootEntry As New DirectoryEntry(LDAP://ADservername, "username","password")
See: http://www.codeproject.com/aspnet/ac...rectoryuse.asp
Juan T. Llibre ASP.NET MVP =========== "JIM.H." <JI**@discussions.microsoft.com> wrote in message news:66**********************************@microsof t.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**@discussions.microsoft.com> wrote in message >> news:61**********************************@microsof t.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.EventArgs) 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 DirectorySearcher(rootEntry) >> > searcher.PropertiesToLoad.Add("mail") >> > >> > Dim results As SearchResultCollection >> > results = searcher.FindAll() >> > >> > Dim result As SearchResult >> > >> > For Each result In results >> > Response.Write(result.Properties("mail")(0)) >> > Next >> > >> > End Sub >> > >> > I got "Object reference not set to an instance of an object" at line >> > Response.Write(result.Properties("mail")(0)), what am I missing? >> > Thanks, >> > Jim. >> > >> > >> > >> >> >>
Juan,
I use this at the filter
searcher.Filter = "(&(anr=myUser)(objectCategory=person))"
and this to see the result,
Response.Write(result.Properties("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.GetDirectoryEntry.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 objectCategories at: http://dotnetjunkies.com/WebLog/bria.../31/40012.aspx
Juan T. Llibre ASP.NET MVP =========== "JIM.H." <JI**@discussions.microsoft.com> wrote in message news:D5**********************************@microsof t.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.EventArgs) 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 DirectorySearcher(rootEntry) searcher.PropertiesToLoad.Add("cn") searcher.PropertiesToLoad.Add("mail")
searcher.Filter = "(&(anr=myUser)(objectCategory=person))"
Dim results As SearchResultCollection results = searcher.FindAll()
Dim result As SearchResult
For Each result In results Response.Write(result.GetDirectoryEntry.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","password"); > > VB.NET > Dim rootEntry As New DirectoryEntry(LDAP://ADservername, > "username","password") > > See: > http://www.codeproject.com/aspnet/ac...rectoryuse.asp > > > > > > Juan T. Llibre > ASP.NET MVP > =========== > "JIM.H." <JI**@discussions.microsoft.com> wrote in message > news:66**********************************@microsof t.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**@discussions.microsoft.com> wrote in message > >> news:61**********************************@microsof t.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.EventArgs) 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 DirectorySearcher(rootEntry) > >> > searcher.PropertiesToLoad.Add("mail") > >> > > >> > Dim results As SearchResultCollection > >> > results = searcher.FindAll() > >> > > >> > Dim result As SearchResult > >> > > >> > For Each result In results > >> > Response.Write(result.Properties("mail")(0)) > >> > Next > >> > > >> > End Sub > >> > > >> > I got "Object reference not set to an instance of an object" at line > >> > Response.Write(result.Properties("mail")(0)), what am I missing? > >> > Thanks, > >> > Jim. > >> > > >> > > >> > > >> > >> > >> > > >
Try
Response.Write(Result.GetDirectoryEntry().Properti es("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**@discussions.microsoft.com> wrote in message
news:76**********************************@microsof t.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.GetDirectoryEntry.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 objectCategories at: http://dotnetjunkies.com/WebLog/bria.../31/40012.aspx
Juan T. Llibre ASP.NET MVP =========== "JIM.H." <JI**@discussions.microsoft.com> wrote in message news:D5**********************************@microsof t.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.EventArgs) 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 DirectorySearcher(rootEntry) > searcher.PropertiesToLoad.Add("cn") > searcher.PropertiesToLoad.Add("mail") > > searcher.Filter = "(&(anr=myUser)(objectCategory=person))" > > Dim results As SearchResultCollection > results = searcher.FindAll() > > Dim result As SearchResult > > For Each result In results > Response.Write(result.GetDirectoryEntry.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","password"); >> >> VB.NET >> Dim rootEntry As New DirectoryEntry(LDAP://ADservername, >> "username","password") >> >> See: >> http://www.codeproject.com/aspnet/ac...rectoryuse.asp >> >> >> >> >> >> Juan T. Llibre >> ASP.NET MVP >> =========== >> "JIM.H." <JI**@discussions.microsoft.com> wrote in message >> news:66**********************************@microsof t.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**@discussions.microsoft.com> wrote in message >> >> news:61**********************************@microsof t.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.EventArgs) 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 DirectorySearcher(rootEntry) >> >> > searcher.PropertiesToLoad.Add("mail") >> >> > >> >> > Dim results As SearchResultCollection >> >> > results = searcher.FindAll() >> >> > >> >> > Dim result As SearchResult >> >> > >> >> > For Each result In results >> >> > Response.Write(result.Properties("mail")(0)) >> >> > Next >> >> > >> >> > End Sub >> >> > >> >> > I got "Object reference not set to an instance of an object" at >> >> > line >> >> > Response.Write(result.Properties("mail")(0)), what am I missing? >> >> > Thanks, >> >> > Jim. >> >> > >> >> > >> >> > >> >> >> >> >> >> >> >> >>
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.Properties("mail")(0)) Then
result.Properties("mail")(0) = " "
else
Response.Write(result.Properties("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**@discussions.microsoft.com> wrote in message
news:2C**********************************@microsof t.com... Juan, I use this at the filter searcher.Filter = "(&(anr=myUser)(objectCategory=person))" and this to see the result, Response.Write(result.Properties("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.GetDirectoryEntry.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 objectCategories at: > http://dotnetjunkies.com/WebLog/bria.../31/40012.aspx > > > > > Juan T. Llibre > ASP.NET MVP > =========== > "JIM.H." <JI**@discussions.microsoft.com> wrote in message > news:D5**********************************@microsof t.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.EventArgs) 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 DirectorySearcher(rootEntry) > > searcher.PropertiesToLoad.Add("cn") > > searcher.PropertiesToLoad.Add("mail") > > > > searcher.Filter = "(&(anr=myUser)(objectCategory=person))" > > > > Dim results As SearchResultCollection > > results = searcher.FindAll() > > > > Dim result As SearchResult > > > > For Each result In results > > Response.Write(result.GetDirectoryEntry.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","password"); > >> > >> VB.NET > >> Dim rootEntry As New DirectoryEntry(LDAP://ADservername, > >> "username","password") > >> > >> See: > >> http://www.codeproject.com/aspnet/ac...rectoryuse.asp > >> > >> > >> > >> > >> > >> Juan T. Llibre > >> ASP.NET MVP > >> =========== > >> "JIM.H." <JI**@discussions.microsoft.com> wrote in message > >> news:66**********************************@microsof t.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**@discussions.microsoft.com> wrote in message > >> >> news:61**********************************@microsof t.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.EventArgs) 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 DirectorySearcher(rootEntry) > >> >> > searcher.PropertiesToLoad.Add("mail") > >> >> > > >> >> > Dim results As SearchResultCollection > >> >> > results = searcher.FindAll() > >> >> > > >> >> > Dim result As SearchResult > >> >> > > >> >> > For Each result In results > >> >> > Response.Write(result.Properties("mail")(0)) > >> >> > Next > >> >> > > >> >> > End Sub > >> >> > > >> >> > I got "Object reference not set to an instance of an object" at > >> >> > line > >> >> > Response.Write(result.Properties("mail")(0)), what am I > >> >> > missing? > >> >> > Thanks, > >> >> > Jim. > >> >> > > >> >> > > >> >> > > >> >> > >> >> > >> >> > >> > >> > >> > > > This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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.
...
|
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...
|
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...
|
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...
|
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 =...
|
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...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shllpp 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |