Hi all...
Please help me out..... In TROUBLE ONCE AGAIN....
My Requirements -
1. Active Directory
1.1. Get a list of all the users from the active director in Windows 7 and Windows 8.
1.2. Display them in GridView and also insert those users in SQL Server Table.
2. Domain (in.abc.com)
2.1. Domain name is present in Right Click on My Computers.
2.2. Get a list of all the users in that particular domain.
2.3. Display them in GridView and also insert those in SQL Server Table.
------------
How to get these users from asp.net c# coding ????
Please help !!
Loading

Sibeesh VenuRank #27 · 42.9K reputationPosted Dec 25, 2014, 7:48 AM EST
If you ever need to list the user in a domain. For example Artinsoft.com this is code might be helpful
public static void Main()
{
var ctx = new PrincipalContext(ContextType.Domain,"Artinsoft", "DC=artinsoft,DC=com"); UserPrincipal userPrin = new UserPrincipal(ctx);
userPrin.Name = "*";
var searcher = new System.DirectoryServices.AccountManagement.PrincipalSearcher(); searcher.QueryFilter = userPrin;
var results = searcher.FindAll();
foreach (Principal p in results)
{
Console.WriteLine("Name:{0},Account={1},DisplayName={2},Distinguish={3}",
p.Name, p.SamAccountName, p.DisplayName,
p.DistinguishedName);
}
}
Riddhi ValechaRank #794 · 2.9K reputationPosted Dec 25, 2014, 6:19 PM EST
Thanks a ton... I tried this code...
But, I still did not get the list of users of Artinsoft.
My Requirement -
string Domain = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;
-----
Get all the users from this domain.
----------
Path -
Control Panel -> Programs and Features -> Turn Windows Features on or off ->
----------
Please guide. Its imp and urgent.
Please help.
Riddhi ValechaRank #794 · 2.9K reputationPosted Dec 26, 2014, 2:22 AM EST
Please guide - IMP
I tried the following for Domain Users -
public class Example
{
public List
{
List
using (var ctx= new PrincipalContext(ContextType.Domain, "your domain name"))
{
using (var PSearcher= new PrincipalSearcher(new UserPrincipal(ctx)))
{
foreach (var account in PSearcher.FindAll())
{
string Name = Convert.ToString(account.DisplayName);
string SAMAccountName = Convert.ToString(account.SamAccountName);
string EmailAddress = Convert.ToString(account.UserPrincipalName);
users.Add(new ADUsers() { Name = Name, SAMAccountName= SAMAccountName, Email = EmailAddress });
}
}
}
return users;
}
}
public class ADUsers
{
public string Name { get; set; }
public string SAMAccountName { get; set; }
public string Email { get; set; }
}
-----
I am getting an error - Cannot convert byte[] to string.
-------
My Requirement -
string Domain = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;
-----
Get all the users from this domain.
Please guide... IT is on urgent basis. It is imp.