New to
New to
New to
New to
New to
New to New to New to New to New to New to New to New to
New to New to
New to
Go Back  Xtreme Visual Basic Talk > > > New to

Thread Tools Display Modes
Old 06-19-2008, 06:58 AM
jagoh87 jagoh87 is offline
Join Date: Sep 2005
Location: Hull, Yorkshire
Posts: 90
Default New to

My boss has asked me to take a look at creating a site that will list all the users in our AD tree.

I created a few vb .net applications doing this sort of thing so im familiar with that.

What i have so far is a dropdownlist with a button, on the form load it populates the dropdownlist with all our users.

what i then want is to click the button and to display the details(name, email etc) for the user.

This is what i have so far

Imports System.DirectoryServices
Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub

    Public Function getaduserlist() As ArrayList
        getaduserlist = New ArrayList
        Dim DE As DirectoryEntry = New DirectoryEntry("LDAP://OU=xxxxxxxx,DC=xxxxxxxx,DC=com")
        Dim mySearcher As DirectorySearcher = New DirectorySearcher(DE)
        mySearcher.Filter = ("OU=*")
        Dim resEnt As SearchResult
        For Each resEnt In mySearcher.FindAll()
            If resEnt.GetDirectoryEntry.Name.Contains("Workstations") = False _
            AndAlso resEnt.GetDirectoryEntry.Name.Contains("Laptops") = False _
            AndAlso resEnt.GetDirectoryEntry.Name.Contains("Printers") = False _
            AndAlso resEnt.GetDirectoryEntry.Name.Contains("Groups") = False _
            AndAlso resEnt.GetDirectoryEntry.Name.Contains("Contacts") = False _
            AndAlso resEnt.GetDirectoryEntry.Name.Contains("Agents") = False _
            AndAlso resEnt.GetDirectoryEntry.Name.Contains("System") = False _
            AndAlso resEnt.GetDirectoryEntry.Name.Contains("Computers") = False Then
                Dim entry As DirectoryEntry = New DirectoryEntry(resEnt.GetDirectoryEntry.Path)
                Dim Searcher As DirectorySearcher = New DirectorySearcher(entry)
                Searcher.Filter = "(&(objectClass=user)(objectCategory=person))"
                For Each resEntry As SearchResult In Searcher.FindAll()
                    Dim de2 As DirectoryEntry = resEntry.GetDirectoryEntry
                    DropDownList1.Items.Add(de2.Properties("DisplayName").Value.ToString() & " (" & de2.Properties("samAccountName").Value.ToString & ")")
            End If
        Return getaduserlist
    End Function

    Private Sub sortlistitems(ByVal list As Object)
        Dim li As ListItem
        Dim sl As SortedList = New SortedList
        For Each li In list.items
            sl.Add(li.Text, li.Value)
        list.datasource = sl
        list.datavaluefield = "value"
        list.datatextfield = "key"
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

    End Sub
End Class
HTML Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="contacts_home.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
    <style type="text/css">
            font-family: Arial, Helvetica, sans-serif;
            font-weight: bold;
            font-size: small;
            width: 301px;
    <form id="form1" runat="server">
  <div align="left">
        <td valign="top">People
          <ul id="list-menu" style="list-style-image: &gt;">
            <li class="style1"><a href="home.aspx" target="mainFrame">Home</a></li>
            <li class="style1"><a href="search.aspx" target="mainFrame">Search</a></li>
            <li class="style1"><a href="by_department.aspx" target="mainFrame">List By Office</a></li>
            <li class="style1"><a href="by_name.aspx" target="mainFrame">List By Name</a></li>
        <td class="style2"><table width="100%">
              <td bgcolor="#CCCCCC"><div align="center">Quick Lookup </div></td>
                  <div align="center" style="width: 519px"> Select User ID
                      <asp:DropDownList ID="DropDownList1" runat="server" Width="303px">
                      <asp:Button ID="Button1" runat="server" Text="Look Up" Width="79px" />
Any help in guiding me on how to do this would be great
Reply With Quote
Old 06-24-2008, 11:57 AM
lebb's Avatar
lebbNew to lebb is offline
Disillusioned Code Poet

Retired Moderator
* Guru *
Join Date: Apr 2002
Location: Tennessee, USA
Posts: 12,808

First off, Page_Load is going to fire every time your page is loaded, including when the button is clicked (before its Click event fires). So you'll want to move your code there inside an If Not IsPostBack block so that it only runs the first time the page is loaded.

Next, I'd recommend adding a panel to your page (you can do that in the designer or code the HTML directly), then drag labels or textboxes onto it for the detail display you want. Set the panel's Visible property to False. Then in your button's Click event handler, you can populate those controls and show the panel by setting its Visible property back to true.

Ita erat quando hic adveni.
Reply With Quote

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
New to
New to
New to New to
New to
New to
New to New to New to New to New to New to New to
New to
New to
New to
New to