I haven't found exactly what I've been trying to do.
All I am trying to do for now is just display usernames from Active
Directory into a ListBox control on a page. I have found some code
however that will just capture a Full Name from Text Box and display
information from the Active Directory into a DataTable. I will display
that code below.
How can I change this code to make it display on the Page Load all
users into a ListBox control?
Here is what I have right now that I was to change to make it work in a
listbox and not rely on the entry from the textbox...
<!--Beginning of Page -->
<%@ Page Language="C#" %>
<%@ Import Namespace="Syst em.DirectorySer vices" %>
<%@ Import Namespace="Syst em.Configuratio n" %>
<%@ Import Namespace="Syst em.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<style type="text/css">
body {
font-family: Arial, Verdana;
font-size: 11pt;
font-color: #000000;
margin: 0;
padding: 0 10px 0 10px;
text-align: left
}
</style>
</head>
<body>
<form id="Form1" runat="server">
<asp:ScriptMana ger ID="AtlasScript Core" runat="server"
EnablePartialRe ndering="true" />
<div id="content">
<h3>
Active Directory Searcher</h3>
<div id="searchbox" >
Type Users Surname<br />
<asp:TextBox ID="txtFullName " runat="server">
</asp:TextBox>
<asp:Button ID="btnDetails " runat="server" Text="Get AD
Details" OnClick="GetADD etails" />
</div><br />
<div id="Results">
<asp:UpdatePane l ID="UpdatePanel 1" runat="server"
UpdateMode="Con ditional">
<ContentTemplat e>
<asp:GridView ID="ADUserPrope rties"
runat="server">
</asp:GridView>
<asp:Literal runat="server" ID="SysMessage "
EnableViewState ="false" ></asp:Literal>
</ContentTemplate >
<Triggers>
<asp:PostBackTr igger ControlID="btnD etails" />
</Triggers>
</asp:UpdatePanel >
</div>
</div>
</form>
</body>
</html>
<script runat="server">
protected void GetADDetails(Ob ject sender , EventArgs e )
{
// Take the value from the input box and pull back a few AD
details
DataTable UserProperties = null;
UserProperties = GetUserByDispla yName(txtFullNa me.Text);
// Display data if we have any or show warning
if (UserProperties != null)
{
ADUserPropertie s.DataSource = UserProperties;
ADUserPropertie s.DataBind();
}
else
{
// Show no records
SysMessage.Text = "<p style=\"color: red;\">Could not find
any details for this user. <br />" +
"Please check that the users name is
correct.</p>";
}
}
protected DataTable GetUserByDispla yName(String fullUserName)
{
DirectoryEntry de = new
DirectoryEntry( ConfigurationMa nager.AppSettin gs.Get("ADPath" ));
// Authentication details
de.Username =
ConfigurationMa nager.AppSettin gs.Get("ADServi ceAccount"); //DOMAIN\User
de.Password =
ConfigurationMa nager.AppSettin gs.Get("ADServi ceAccountPasswo rd");
de.Authenticati onType = AuthenticationT ypes.FastBind;
DirectorySearch er DirectorySearch er = new
DirectorySearch er(de);
DirectorySearch er.ClientTimeou t = TimeSpan.FromSe conds(30);
// load the properties we are interested in
DirectorySearch er.PropertiesTo Load.Add("cn");
DirectorySearch er.PropertiesTo Load.Add("sAMAc countName");
DirectorySearch er.PropertiesTo Load.Add("mail" );
DirectorySearch er.PropertiesTo Load.Add("displ ayName");
DirectorySearch er.PropertiesTo Load.Add("mDBSt orageQuota");
DirectorySearch er.PropertiesTo Load.Add("title ");
DirectorySearch er.PropertiesTo Load.Add("physi calDeliveryOffi ceName");
DirectorySearch er.PropertiesTo Load.Add("telep honeNumber");
// filter it on exact entry - NOTE no wild card
DirectorySearch er.Filter = "(displayNa me=" +
fullUserName.Tr im() + ")";
SearchResult result;
// There should only be one entry
result = DirectorySearch er.FindOne();
if (result != null)
{
// Create a table an populate it with properties to bind to
gridview
DataTable myTable = new DataTable("Acti veDir");
myTable.Columns .Add(new DataColumn("Key ",
System.Type.Get Type("System.St ring")));
myTable.Columns .Add(new DataColumn("Val ue",
System.Type.Get Type("System.St ring")));
DataRow myRow;
foreach (string propname in
result.Properti es.PropertyName s)
{
foreach (Object objValue in
result.Properti es[propname])
{
myRow = myTable.NewRow( );
myRow[0] = propname;
myRow[1] = objValue.ToStri ng();
myTable.Rows.Ad d(myRow);
}
}
return myTable;
}
else
{
return null;
}
}
<!--End of Page -->
Any help would greatly appreciated!
Thanks,
Jonathan 2 12003
Check the Datasource and Datamember properties. I do not see any binding
code from below maybe I miss it.
chanmm
<j.**********@g mail.comwrote in message
news:11******** *************@f 1g2000cwa.googl egroups.com...
>I haven't found exactly what I've been trying to do.
All I am trying to do for now is just display usernames from Active
Directory into a ListBox control on a page. I have found some code
however that will just capture a Full Name from Text Box and display
information from the Active Directory into a DataTable. I will display
that code below.
How can I change this code to make it display on the Page Load all
users into a ListBox control?
Here is what I have right now that I was to change to make it work in a
listbox and not rely on the entry from the textbox...
<!--Beginning of Page -->
<%@ Page Language="C#" %>
<%@ Import Namespace="Syst em.DirectorySer vices" %>
<%@ Import Namespace="Syst em.Configuratio n" %>
<%@ Import Namespace="Syst em.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<style type="text/css">
body {
font-family: Arial, Verdana;
font-size: 11pt;
font-color: #000000;
margin: 0;
padding: 0 10px 0 10px;
text-align: left
}
</style>
</head>
<body>
<form id="Form1" runat="server">
<asp:ScriptMana ger ID="AtlasScript Core" runat="server"
EnablePartialRe ndering="true" />
<div id="content">
<h3>
Active Directory Searcher</h3>
<div id="searchbox" >
Type Users Surname<br />
<asp:TextBox ID="txtFullName " runat="server">
</asp:TextBox>
<asp:Button ID="btnDetails " runat="server" Text="Get AD
Details" OnClick="GetADD etails" />
</div><br />
<div id="Results">
<asp:UpdatePane l ID="UpdatePanel 1" runat="server"
UpdateMode="Con ditional">
<ContentTemplat e>
<asp:GridView ID="ADUserPrope rties"
runat="server">
</asp:GridView>
<asp:Literal runat="server" ID="SysMessage "
EnableViewState ="false" ></asp:Literal>
</ContentTemplate >
<Triggers>
<asp:PostBackTr igger ControlID="btnD etails" />
</Triggers>
</asp:UpdatePanel >
</div>
</div>
</form>
</body>
</html>
<script runat="server">
protected void GetADDetails(Ob ject sender , EventArgs e )
{
// Take the value from the input box and pull back a few AD
details
DataTable UserProperties = null;
UserProperties = GetUserByDispla yName(txtFullNa me.Text);
// Display data if we have any or show warning
if (UserProperties != null)
{
ADUserPropertie s.DataSource = UserProperties;
ADUserPropertie s.DataBind();
}
else
{
// Show no records
SysMessage.Text = "<p style=\"color: red;\">Could not find
any details for this user. <br />" +
"Please check that the users name is
correct.</p>";
}
}
protected DataTable GetUserByDispla yName(String fullUserName)
{
DirectoryEntry de = new
DirectoryEntry( ConfigurationMa nager.AppSettin gs.Get("ADPath" ));
// Authentication details
de.Username =
ConfigurationMa nager.AppSettin gs.Get("ADServi ceAccount"); //DOMAIN\User
de.Password =
ConfigurationMa nager.AppSettin gs.Get("ADServi ceAccountPasswo rd");
de.Authenticati onType = AuthenticationT ypes.FastBind;
DirectorySearch er DirectorySearch er = new
DirectorySearch er(de);
DirectorySearch er.ClientTimeou t = TimeSpan.FromSe conds(30);
// load the properties we are interested in
DirectorySearch er.PropertiesTo Load.Add("cn");
DirectorySearch er.PropertiesTo Load.Add("sAMAc countName");
DirectorySearch er.PropertiesTo Load.Add("mail" );
DirectorySearch er.PropertiesTo Load.Add("displ ayName");
DirectorySearch er.PropertiesTo Load.Add("mDBSt orageQuota");
DirectorySearch er.PropertiesTo Load.Add("title ");
DirectorySearch er.PropertiesTo Load.Add("physi calDeliveryOffi ceName");
DirectorySearch er.PropertiesTo Load.Add("telep honeNumber");
// filter it on exact entry - NOTE no wild card
DirectorySearch er.Filter = "(displayNa me=" +
fullUserName.Tr im() + ")";
SearchResult result;
// There should only be one entry
result = DirectorySearch er.FindOne();
if (result != null)
{
// Create a table an populate it with properties to bind to
gridview
DataTable myTable = new DataTable("Acti veDir");
myTable.Columns .Add(new DataColumn("Key ",
System.Type.Get Type("System.St ring")));
myTable.Columns .Add(new DataColumn("Val ue",
System.Type.Get Type("System.St ring")));
DataRow myRow;
foreach (string propname in
result.Properti es.PropertyName s)
{
foreach (Object objValue in
result.Properti es[propname])
{
myRow = myTable.NewRow( );
myRow[0] = propname;
myRow[1] = objValue.ToStri ng();
myTable.Rows.Ad d(myRow);
}
}
return myTable;
}
else
{
return null;
}
}
<!--End of Page -->
Any help would greatly appreciated!
Thanks,
Jonathan
No this code works just want to show all the AD users in a listbox
instead of the datatable shown above.
Jonathan
Chan Ming Man wrote:
Check the Datasource and Datamember properties. I do not see any binding
code from below maybe I miss it.
chanmm
<j.**********@g mail.comwrote in message
news:11******** *************@f 1g2000cwa.googl egroups.com...
I haven't found exactly what I've been trying to do.
All I am trying to do for now is just display usernames from Active
Directory into a ListBox control on a page. I have found some code
however that will just capture a Full Name from Text Box and display
information from the Active Directory into a DataTable. I will display
that code below.
How can I change this code to make it display on the Page Load all
users into a ListBox control?
Here is what I have right now that I was to change to make it work in a
listbox and not rely on the entry from the textbox...
<!--Beginning of Page -->
<%@ Page Language="C#" %>
<%@ Import Namespace="Syst em.DirectorySer vices" %>
<%@ Import Namespace="Syst em.Configuratio n" %>
<%@ Import Namespace="Syst em.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<style type="text/css">
body {
font-family: Arial, Verdana;
font-size: 11pt;
font-color: #000000;
margin: 0;
padding: 0 10px 0 10px;
text-align: left
}
</style>
</head>
<body>
<form id="Form1" runat="server">
<asp:ScriptMana ger ID="AtlasScript Core" runat="server"
EnablePartialRe ndering="true" />
<div id="content">
<h3>
Active Directory Searcher</h3>
<div id="searchbox" >
Type Users Surname<br />
<asp:TextBox ID="txtFullName " runat="server">
</asp:TextBox>
<asp:Button ID="btnDetails " runat="server" Text="Get AD
Details" OnClick="GetADD etails" />
</div><br />
<div id="Results">
<asp:UpdatePane l ID="UpdatePanel 1" runat="server"
UpdateMode="Con ditional">
<ContentTemplat e>
<asp:GridView ID="ADUserPrope rties"
runat="server">
</asp:GridView>
<asp:Literal runat="server" ID="SysMessage "
EnableViewState ="false" ></asp:Literal>
</ContentTemplate >
<Triggers>
<asp:PostBackTr igger ControlID="btnD etails" />
</Triggers>
</asp:UpdatePanel >
</div>
</div>
</form>
</body>
</html>
<script runat="server">
protected void GetADDetails(Ob ject sender , EventArgs e )
{
// Take the value from the input box and pull back a few AD
details
DataTable UserProperties = null;
UserProperties = GetUserByDispla yName(txtFullNa me.Text);
// Display data if we have any or show warning
if (UserProperties != null)
{
ADUserPropertie s.DataSource = UserProperties;
ADUserPropertie s.DataBind();
}
else
{
// Show no records
SysMessage.Text = "<p style=\"color: red;\">Could not find
any details for this user. <br />" +
"Please check that the users name is
correct.</p>";
}
}
protected DataTable GetUserByDispla yName(String fullUserName)
{
DirectoryEntry de = new
DirectoryEntry( ConfigurationMa nager.AppSettin gs.Get("ADPath" ));
// Authentication details
de.Username =
ConfigurationMa nager.AppSettin gs.Get("ADServi ceAccount"); //DOMAIN\User
de.Password =
ConfigurationMa nager.AppSettin gs.Get("ADServi ceAccountPasswo rd");
de.Authenticati onType = AuthenticationT ypes.FastBind;
DirectorySearch er DirectorySearch er = new
DirectorySearch er(de);
DirectorySearch er.ClientTimeou t = TimeSpan.FromSe conds(30);
// load the properties we are interested in
DirectorySearch er.PropertiesTo Load.Add("cn");
DirectorySearch er.PropertiesTo Load.Add("sAMAc countName");
DirectorySearch er.PropertiesTo Load.Add("mail" );
DirectorySearch er.PropertiesTo Load.Add("displ ayName");
DirectorySearch er.PropertiesTo Load.Add("mDBSt orageQuota");
DirectorySearch er.PropertiesTo Load.Add("title ");
DirectorySearch er.PropertiesTo Load.Add("physi calDeliveryOffi ceName");
DirectorySearch er.PropertiesTo Load.Add("telep honeNumber");
// filter it on exact entry - NOTE no wild card
DirectorySearch er.Filter = "(displayNa me=" +
fullUserName.Tr im() + ")";
SearchResult result;
// There should only be one entry
result = DirectorySearch er.FindOne();
if (result != null)
{
// Create a table an populate it with properties to bind to
gridview
DataTable myTable = new DataTable("Acti veDir");
myTable.Columns .Add(new DataColumn("Key ",
System.Type.Get Type("System.St ring")));
myTable.Columns .Add(new DataColumn("Val ue",
System.Type.Get Type("System.St ring")));
DataRow myRow;
foreach (string propname in
result.Properti es.PropertyName s)
{
foreach (Object objValue in
result.Properti es[propname])
{
myRow = myTable.NewRow( );
myRow[0] = propname;
myRow[1] = objValue.ToStri ng();
myTable.Rows.Ad d(myRow);
}
}
return myTable;
}
else
{
return null;
}
}
<!--End of Page -->
Any help would greatly appreciated!
Thanks,
Jonathan
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Luis Esteban Valencia |
last post by:
Hello gusys, Is it possible to make my asp.net application add users to the
AD , I also want to be able to delete users, modify their information,
everything through a website.
Thanks for the info
|
by: tangus via DotNetMonster.com |
last post by:
Hello all, I'm really struggling with getting some Active Directory code to
work in ASP.NET. Can you please provide assistance? I am executing the
following code:
Dim enTry As DirectoryEntry = New DirectoryEntry("LDAP://domain")
Dim mySearcher As New DirectorySearcher(enTry)
Dim resEnt As SearchResult
mySearcher.Filter =...
|
by: Kooki |
last post by:
Hi,
I am developing a small programme to add ACTIVE DIRECTORY users to another
server. everything works fine .. I get the users from AD using LDAP but while
adding users I need to get the user in the form of Domain\UserName. I get the
domain name of our server but I face another problem which is
our server name is "Preston" which I get it...
|
by: Kooki |
last post by:
Hi,
I am developing a small programme to add ACTIVE DIRECTORY users to another
server. everything works fine .. I get the users from AD using LDAP but while
adding users I need to get the user in the form of Domain\UserName. I get the
domain name of our server but I face another problem which is
our server name is "Preston" which I get it...
|
by: jakobsgaard |
last post by:
It is possible to Map a certificate to a Active Directory User Account from
DotNet?
Please provide an example.
Best regards,
Ejnar Jakobsgaard
-------------------------------------------------
To map a certificate to a user account
Open Active Directory Users and Computers.
| |
by: Lucky |
last post by:
hi guys,
after long long efforts i got access to the active directory for
"Intigrated windows authentication". now i', suppose to get access the
network resources.
the problem is i'm getting access to the active directory but when i
search for some users into the active directory, it returns none though
there are more then 42 users exists....
|
by: Jim in Arizona |
last post by:
My goal, somehow, is to populate a dropdownlist with all the user names
in active directory. I don't even know where to begin, really.
I added a reference to System.DirectoryServices so I could use the
System.DirectoryServices.ActiveDirectory namespace. I don't even know if
this is the right way to go as I can't seem to find anything in that...
|
by: CoolBreeze812 |
last post by:
Hello,
I'm using the following code to get the list of computers joined to a
domain in Active Directory and using the System.DirectoryServices
namespace.
DirectoryEntry dirEntry = new DirectoryEntry("LDAP://spencenet.com");
DirectorySearcher dirSearch = new
DirectorySearcher(dirEntry);
dirSearch.Filter = "(objectClass=Computer)";
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |