473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Load Users from Active Directory

I posted this in another group as well...but now I am trying my luck
here...

I have followign method which loads users from active directory

private List<StringGetUserLoginsFromAD()
{
List<Stringresults = new List<string>();

DirectorySearcher srch = new DirectorySearcher();
srch.Filter = "(&(objectClass=user)(objectCategory=person))" ;

//srch.SizeLimit = 100000;
SearchResultCollection sResult = srch.FindAll();

if (null != sResult)
for (int i = 0; i < sResult.Count; i++)
if (null != sResult[i].Properties["SAMAccountName"] &&
sResult[i].Properties["SAMAccountName"].Count == 1)
results.Add(sResult[i].Properties["SAMAccountName"]
[0] as String);

return results;
}

But it throws an exception "A device attached to the system is not
functioning. " when it hits sResult.Count.

Any help will be appreciated.

Thanks
Dec 10 '07 #1
1 3227
"Sehboo" <Ma*********@gmail.comwrote in message
news:bf**********************************@18g2000h sf.googlegroups.com...
>I posted this in another group as well...but now I am trying my luck
here...

I have followign method which loads users from active directory

private List<StringGetUserLoginsFromAD()
{
List<Stringresults = new List<string>();

DirectorySearcher srch = new DirectorySearcher();
srch.Filter = "(&(objectClass=user)(objectCategory=person))" ;

//srch.SizeLimit = 100000;
SearchResultCollection sResult = srch.FindAll();

if (null != sResult)
for (int i = 0; i < sResult.Count; i++)
if (null != sResult[i].Properties["SAMAccountName"] &&
sResult[i].Properties["SAMAccountName"].Count == 1)
results.Add(sResult[i].Properties["SAMAccountName"]
[0] as String);

return results;
}

But it throws an exception "A device attached to the system is not
functioning. " when it hits sResult.Count.

Any help will be appreciated.

Thanks

Don't know what could be the reason for the exception, and I doubt it's
"Count" property which throws an exception. Anyway you are complicating
matters which makes your code less readable, herewith a simplified code
snippet that does exactly what you are looking for:

// get only the samAccountName attribute from the AD
string[] props = {"samaccountname"};
srch.PropertiesToLoad.AddRange(props);
...
SearchResultCollection sResult = srch.FindAll();
foreach(SearchResult sr in sResult )
{
results.Add(sr.Properties["samaccountname"][0].ToString());
}
return results;

Willy.

Dec 10 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ouaes Jamali | last post by:
Hi all, I am trying to set the "Filter" property of directory search object so that the search returns only users that are not disabled in Active Directory? Currently the way i do this to make a...
2
by: duncan | last post by:
Hi I an a mebie to XML / vb.net and I am struggling. I am developing a web base applcation using XML to link to its database so. Here is the XML I want to load into to a datagrid. The...
7
by: Sync Walantaji | last post by:
Hi, I would like to write a asp.net winform program to authenticate users on Active Directory. Can I do this with asp.net if the IIS server is not part of the Active directory domain? Is...
6
by: dhnriverside | last post by:
Hi peeps Ok, I've got a web application running (lets call it MyApp, so its namespace is MyApp). I've created a subdirectory within this application called "secure", and made than an Application...
6
by: Mr Newbie | last post by:
Hi, Im in a situation where I need to restrict users, but I dont have access or wont be allowed access to manage groups in the domain. How can I restrict access is this case ? -- Best...
2
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...
3
by: Chakkaradeep | last post by:
Hi all, How to retrieve Users Names and also restrict internet access to a specific users using C# ? Thanks. Regards, C.C.Chakkaradeep
11
by: frizzle | last post by:
Hi there, I need a function to prevent a page from being loaded too often too fast. So say, one is only allowed to refresh a single page 5 times in 10 seconds, or 10 times in 5 seconds (or...
5
by: ashok90 | last post by:
hi Experts, I want to use Active Directory with C# .Net. My Problem is that i want to restrict some users on my system(which is not on any network) from accessing some applications like oracle,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.