LDAP - Formular -> Browserausgabe

BastiFantasti86

Grünschnabel
Hallo Zusammen!
Ich habe eine kurze frage zu LDAP. Erfolgreich konnte ich schon ein Programm optimieren, was in Form von einem Formular läuft. es ist jedeglich eine ldap abfrage wo man gruppen oder user suchen kann. jetz will ich das Browsermäßig ausgeben lassen damit die Mitarbeiter in der Firma auch davon was haben, kann mir da einer helfen? klingt einfacher als es ist?! danke im voraus
Hier ist das Programm als Bild: http://img232.imageshack.us/img232/638/90086434tj5.jpg

Hier der Quellcode:

Code:
Public Class Form1
  Inherits System.Windows.Forms.Form

#Region " Vom Windows Form Designer generierter Code "

  Public Sub New()
    MyBase.New()

    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents txtServer As System.Windows.Forms.TextBox
    Friend WithEvents txtPfad As System.Windows.Forms.TextBox
    Friend WithEvents txtResult As System.Windows.Forms.TextBox
    Friend WithEvents btnSuchen As System.Windows.Forms.Button
    Friend WithEvents TreeView As System.Windows.Forms.TreeView
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents txtSuche As System.Windows.Forms.TextBox
    Friend WithEvents StatusBar1 As System.Windows.Forms.StatusBar
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.txtServer = New System.Windows.Forms.TextBox
        Me.txtPfad = New System.Windows.Forms.TextBox
        Me.txtResult = New System.Windows.Forms.TextBox
        Me.btnSuchen = New System.Windows.Forms.Button
        Me.TreeView = New System.Windows.Forms.TreeView
        Me.txtSuche = New System.Windows.Forms.TextBox
        Me.Label5 = New System.Windows.Forms.Label
        Me.StatusBar1 = New System.Windows.Forms.StatusBar
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(8, 16)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(72, 16)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "LDAP Server"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(8, 40)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(72, 16)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "Pfad"
        '
        'txtServer
        '
        Me.txtServer.Location = New System.Drawing.Point(88, 16)
        Me.txtServer.Name = "txtServer"
        Me.txtServer.Size = New System.Drawing.Size(440, 20)
        Me.txtServer.TabIndex = 4
        Me.txtServer.Text = "LDAP:// "
        '
        'txtPfad
        '
        Me.txtPfad.Location = New System.Drawing.Point(88, 40)
        Me.txtPfad.Name = "txtPfad"
        Me.txtPfad.Size = New System.Drawing.Size(440, 20)
        Me.txtPfad.TabIndex = 5
        Me.txtPfad.Text = "OU= "
        '
        'txtResult
        '
        Me.txtResult.Font = New System.Drawing.Font("Courier New", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtResult.Location = New System.Drawing.Point(24, 304)
        Me.txtResult.Multiline = True
        Me.txtResult.Name = "txtResult"
        Me.txtResult.ScrollBars = System.Windows.Forms.ScrollBars.Both
        Me.txtResult.Size = New System.Drawing.Size(704, 216)
        Me.txtResult.TabIndex = 9
        Me.txtResult.Text = ""
        Me.txtResult.WordWrap = False
        '
        'btnSuchen
        '
        Me.btnSuchen.Location = New System.Drawing.Point(80, 544)
        Me.btnSuchen.Name = "btnSuchen"
        Me.btnSuchen.Size = New System.Drawing.Size(520, 24)
        Me.btnSuchen.TabIndex = 10
        Me.btnSuchen.Text = "&Suchen"
        '
        'TreeView
        '
        Me.TreeView.ImageIndex = -1
        Me.TreeView.Location = New System.Drawing.Point(24, 136)
        Me.TreeView.Name = "TreeView"
        Me.TreeView.SelectedImageIndex = -1
        Me.TreeView.Size = New System.Drawing.Size(704, 152)
        Me.TreeView.TabIndex = 11
        '
        'txtSuche
        '
        Me.txtSuche.Location = New System.Drawing.Point(88, 112)
        Me.txtSuche.Name = "txtSuche"
        Me.txtSuche.Size = New System.Drawing.Size(440, 20)
        Me.txtSuche.TabIndex = 12
        Me.txtSuche.Text = "(cn=*)"
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(8, 112)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(72, 16)
        Me.Label5.TabIndex = 13
        Me.Label5.Text = "Abfrage"
        '
        'StatusBar1
        '
        Me.StatusBar1.Location = New System.Drawing.Point(0, 570)
        Me.StatusBar1.Name = "StatusBar1"
        Me.StatusBar1.Size = New System.Drawing.Size(754, 22)
        Me.StatusBar1.TabIndex = 14
        Me.StatusBar1.Text = "StatusBar1"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(754, 592)
        Me.Controls.Add(Me.StatusBar1)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.txtSuche)
        Me.Controls.Add(Me.TreeView)
        Me.Controls.Add(Me.btnSuchen)
        Me.Controls.Add(Me.txtResult)
        Me.Controls.Add(Me.txtPfad)
        Me.Controls.Add(Me.txtServer)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = " "
        Me.ResumeLayout(False)

    End Sub

#End Region

  Private Sub btnSuchen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSuchen.Click
    Dim de As DirectoryEntry
    Dim obj, objProp As Object
    Dim searcher As DirectorySearcher
    Dim sr As SearchResultCollection
    Dim res As SearchResult
    Dim tn As TreeNode

    txtResult.Text = ""
    TreeView.Nodes.Clear()
    tn = TreeView.Nodes.Add("Root")

    Try
      If txtUser.Text.Length > 0 Then
        de = New DirectoryEntry("LDAP://" & txtServer.Text & "/" & txtPfad.Text, AuthenticationTypes.ServerBind)
      Else
        de = New DirectoryEntry("LDAP://" & txtServer.Text & "/" & txtPfad.Text)
      End If

      searcher = New DirectorySearcher(de)
      searcher.Filter = txtSuche.Text  '"(&(objectClass=person)(cn=*)"
      'searcher.SearchScope = SearchScope.OneLevel

      sr = searcher.FindAll
      For Each res In sr
        tn.Nodes.Add(res.Path).Tag = res
      Next
      tn.ExpandAll()
    Catch ex As Exception
      txtResult.Text &= ex.Message
    End Try
  End Sub

  Private Sub TreeView_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView.AfterSelect
    Dim NStr As String
    Dim obj As Object
    Try
      If Not e.Node.Tag Is Nothing Then
        txtResult.Text = e.Node.Text & vbCrLf
        For Each NStr In CType(e.Node.Tag, SearchResult).Properties.PropertyNames
          txtResult.Text &= vbCrLf & "--+-> " & NStr & vbCrLf
          For Each obj In CType(e.Node.Tag, SearchResult).Properties(NStr)
            txtResult.Text &= "  |__ " & obj.ToString & vbCrLf
          Next
        Next NStr
      End If
    Catch ex As Exception
      txtResult.Text &= ex.Message
    End Try

  End Sub

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

  End Sub

End Class
 
Zurück