Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Web part to search the active directory

  Asked By: Amolika    Date: Aug 21    Category: Sharepoint    Views: 860

did any body developed a web part that searches the active
directory.
I have the code working in both the windows and web applications,
but it gives a security error when used with a web part.

I'm usig a hash table to bind the data to a datagrid and it stops on
that hash table

Share: 

 

4 Answers Found

 
Answer #1    Answered By: John Scott     Answered On: Aug 21

What error  are you getting???????????

 
Answer #2    Answered By: Donald Torres     Answered On: Aug 21

this is the error

[System.NullReferenceException: Object reference not set to an
instance of an object.]

 
Answer #3    Answered By: Courtney Scott     Answered On: Aug 21

This is too generic to do any good unfortunately. You would probably
need to post code.

 
Answer #4    Answered By: Jagdeep Hor     Answered On: Aug 21

I came to know that my problem will be Probably with the Code Access
Security(CAS) but till now I did not figure out how to implement
that if any body  has gone through that before

And Here is My Code
[ Dim btnsearch As New Button
Dim txtName As New TextBox
Dim dgdetails As New DataGrid
Dim htable As New Hashtable
Dim srchName As String
Dim DS As DataSet

Public Sub btnsearch_clicked(ByVal sender As Object, ByVal e As
EventArgs)
Try
srchName = Trim(txtName.Text)
txtName.Text = Getloggedinuser()
htable = GetEmpName(srchName)
dgdetails.DataSource = htable
dgdetails.DataBind()
Catch ex As Exception
txtName.Text = (ex.ToString)
End Try
End Sub

Protected Overrides Sub Createchildcontrols()
AddHandler btnsearch.Click, AddressOf btnsearch_clicked
With Controls
.Add(btnsearch)
.Add(txtName)
.Add(dgdetails)
End With
End Sub

Protected Overrides Sub RenderWebPart(ByVal output As
System.Web.UI.HtmlTextWriter)
Try
' renderchildren(output)
btnsearch.Text = "Click Here"
output.Write("<table border=1>")
output.Write("<tr><td>")
btnsearch.RenderControl(output)
output.Write("</td><td>")
txtName.RenderControl(output)
output.Write("</td></tr><tr><td colspan=2 height='200'>")
dgdetails.RenderControl(output)
output.Write("</td></tr></table>")
Catch ex As Exception
output.Write(ex.ToString)
End Try
End Sub

Private Function GetEmpName(ByVal sAMAccountName As String) As
Hashtable
Try
Dim EmpName As String
Dim EmpExt As String

htable = New Hashtable
Dim strpath As String = "LDAP://DC=????,DC=?????,DC=net"
Dim DE As New System.DirectoryServices.DirectoryEntry
(strpath, "domainname\UserID", "password")
Dim searcher As New DirectorySearcher(DE)

' searcher.Filter = "(&(objectClass=user)(anr= " &
sAMAccountName & "))"
searcher.Filter = "(&(objectCategory=person)
(objectClass=user)(anr=" & sAMAccountName & " * ))"

For Each result As SearchResult In searcher.FindAll
EmpExt = 0 '(result.Properties("IPphone")(0))
EmpName = (result.Properties("displayName")(0))
htable.Add(EmpName, EmpExt)
Next
Return htable
Catch ex As Exception
txtName.Text = ("In the function:: " + ex.ToString)
End Try
End Function]

 
Didn't find what you were looking for? Find more on Web part to search the active directory Or get search suggestion and latest updates.




Tagged: