1. While I am executing/running this webpage on my laptop...does it have to be connected to the domain of I am trying to access activedirectory?
2. Where do I view the results..I mean how do I view results in my webpage...how do I show all the results in gridview
I am using vb.net and asp.net
<body>
<form id="form1" runat="server">
<span class="code-SummaryComment"><param name="de">DirectoryEntry to use</param></span>
<span class="code-SummaryComment"><param name="pName">Property name to set</param></span>
<span class="code-SummaryComment"><param name="pValue">Value of property to set</param></span>
<div>
<asp:Label ID="Label1" runat="server" Text="IP"> </asp:Label><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text="Username"></asp:Label> <asp:textbox runat="server"></asp:textbox>
<asp:Label ID="Label3" runat="server" Text="Password"></asp:Label><asp:textbox runat="server"></asp:textbox>
<asp:Button ID="Button1" runat="server" Text="Connect" />
</div>
</form>
Public Shared Sub SetADProperty(ByVal de As DirectoryEntry,
ByVal pName As String, ByVal pValue As String)
'First make sure the property value isnt "nothing"
If Not pValue Is Nothing Then
'Check to see if the DirectoryEntry contains this property already
If de.Properties.Contains(pName) Then 'The DE contains this property
'Update the properties value
de.Properties(pName)(0) = pValue
Else 'Property doesnt exist
'Add the property and set it's value
de.Properties(pName).Add(pValue)
End If
End If
End Sub
Public Shared Function GetDirectoryEntry() As DirectoryEntry
Dim dirEntry As DirectoryEntry = New DirectoryEntry()
dirEntry.Path = "LDAP://192.168.0.110/CN=Users;DC=domainname"
dirEntry.Username = "domain\Administrator"
dirEntry.Password = "Password"
Return dirEntry
End Function
Public Function ExtractUserName(ByVal path As String) As String
Dim userPath As String() = path.Split(New Char() {"\"c})
Return userPath((userPath.Length - 1))
End Function
Public Shared Function ListAllADComputers() As Collection
Dim dirEntry As DirectoryEntry = GetDirectoryEntry()
Dim pcList As New Collection()
' 1. Search the Active Directory for all objects with type of computer
Dim dirSearcher As DirectorySearcher = New DirectorySearcher(dirEntry)
dirSearcher.Filter = ("(objectClass=computer)")
' 2. Check the search results
Dim dirSearchResults As SearchResult
' 3. Loop through all the computer names returned
For Each dirSearchResults In dirSearcher.FindAll()
' 4. Check to ensure the computer name isnt already listed in
'the collection
If Not pcList.Contains(dirSearchResults.GetDirectoryEntry().Name.ToString()) Then
' 5. Add the computer name to the collection (since
'it dont already exist)
pcList.Add(dirSearchResults.GetDirectoryEntry().Name.ToString())
End If
Next
' 6. Return the results
Return pcList
End Function
Where do I view the results..I mean how do I view results in my webpage...how do I show all the results in gridview
To display results in GridView, you could specify and code an event handler for the Click event and use the DataBind() method to bind a data source to a GridView control.
Yes I know the syntax I mean in the above code..how do I bind results to gridview...what would be the result of the above code and how do I bind it...for example if result is in @result@ how do I bind this result value to gridview?
You could create a collection of Computer objects. It then simply sets the DataGrid control's DataSource property to the collection. The DataGrid automatically displays the Computer objects' properties.
<asp:GridView ID="gv" runat="server"></asp:GridView>
Public Class Computer
Private m_Name As String
Public Property Name() As String
Get
Return m_Name
End Get
Set(ByVal Value As String)
m_Name = Value
End Set
End Property
Public Sub New(ByVal name As String)
m_Name = name
End Sub
End Class
Dim m_Computers As Collection
m_Computers = New Collection
m_Computers.Add(New Computer("Al"))
m_Computers.Add(New Computer("Bo"))
m_Computers.Add(New Computer("Cy"))
m_Computers.Add(New Computer("Di"))
gv.DataSource = m_Computers
gv.DataBind()
Member
200 Points
691 Posts
how to get results of this in gridview
Jan 16, 2017 10:49 AM|Lexi85|LINK
Hello All
I have below code...I have 2 question here
1. While I am executing/running this webpage on my laptop...does it have to be connected to the domain of I am trying to access activedirectory?
2. Where do I view the results..I mean how do I view results in my webpage...how do I show all the results in gridview
I am using vb.net and asp.net
All-Star
17652 Points
3510 Posts
Re: how to get results of this in gridview
Jan 18, 2017 03:16 AM|Chris Zhao|LINK
Hi Lexi85,
To display results in GridView, you could specify and code an event handler for the Click event and use the DataBind() method to bind a data source to a GridView control.
Best Regards,
Chris
Member
200 Points
691 Posts
Re: how to get results of this in gridview
Jan 18, 2017 07:51 AM|Lexi85|LINK
Yes I know the syntax I mean in the above code..how do I bind results to gridview...what would be the result of the above code and how do I bind it...for example if result is in @result@ how do I bind this result value to gridview?
All-Star
17652 Points
3510 Posts
Re: how to get results of this in gridview
Jan 19, 2017 02:55 AM|Chris Zhao|LINK
Hi Lexi85,
You could create a collection of Computer objects. It then simply sets the DataGrid control's DataSource property to the collection. The DataGrid automatically displays the Computer objects' properties.
reference: http://www.aspsnippets.com/Articles/How-to-bind-GridView-with-Generic-List-in-ASPNet-using-C-and-VBNet.aspx
Best Regards,
Chris