DirectoryService Problem...

G

Guest

Hi can someone please tell me how I get the username only into a datagrid I
have created to show all the Active Directory Users! At the moment the only
thing I can get to appear in the datagrid is the AD path!

E.G:
<%# Container.DataItem.path%>


Can someone please advise...
I'm new to DirectoryServices and am trying to create a small app to edit
some of the users info in the AD... Any tips and good websites would be
really appritiated! Preferably in VB.NET

Thanks


' CODEBEHIND
Sub GetUserADInfo()
Dim strUserName As String
Dim strADPath As String

strUserName = "netadmin" 'HttpContext.Current.User.Identity.Name
strADPath = "netdomain.domain.dk"


Dim Entry As DirectoryEntry = New DirectoryEntry("LDAP://" &
strADPath, "username", "xxxxxxx")
' Create a DirectorySearcher object.
Dim mySearcher As New DirectorySearcher(Entry)
' Use the FindOne method to find the object, which in this case, is
the user
' indicated by User Name and assign it to a SearchResult.
mySearcher.Filter = ("(&(objectCategory=person)(objectClass=user))")
'Dim MySearchResult As SearchResult = mySearcher.FindOne
Dim results As SearchResultCollection

results = mySearcher.FindAll()
dgADUserInfo.DataSource = results
dgADUserInfo.DataBind()

End Sub
 
G

Guest

OK I think I might have resolved my own problem!

<%#Container.DataItem.GetDirectoryEntry().Name%>

However all my results have CN= on! Is there a way to trim this off in the
Inline code?

EG:

CN=Joe Bloggs

Thanks
 
K

Ken Cox [Microsoft MVP]

Hi Tim,

Will an inline Replace() work?

<%#Replace(Container.DataItem.GetDirectoryEntry().Name,"CN=","") %>

It sounds like you're making good progress with that project.

Ken
Microsoft MVP [ASP.NET]
Toronto
 
G

Guest

That is exactly what I needed!
Thanks...

Funny how you forget simple things like that sometimes!

Cheers



Ken Cox said:
Hi Tim,

Will an inline Replace() work?

<%#Replace(Container.DataItem.GetDirectoryEntry().Name,"CN=","") %>

It sounds like you're making good progress with that project.

Ken
Microsoft MVP [ASP.NET]
Toronto


Tim::.. said:
OK I think I might have resolved my own problem!

<%#Container.DataItem.GetDirectoryEntry().Name%>

However all my results have CN= on! Is there a way to trim this off in the
Inline code?

EG:

CN=Joe Bloggs

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,709
Latest member
AustinMudi

Latest Threads

Top