Click here to Skip to main content
15,947,411 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,

Please Help Me.

I need to get the SAMAccountName by checking with description.

I will get employeeID from Oracle db with that employeeID i need toget the ActiveDirectory Username

Thanks in Advance
Sanju
Posted
Updated 1-Jul-12 23:40pm
v3
Comments
Bernhard Hiller 21-Jun-12 6:41am    
? That's a very strange way to do things. Are you sure?
I'd rather expect to get a username from the Oracle database with the help of the employeeID, and then use that username to authenticate the user against the Active Directory...
Sanju TV 21-Jun-12 7:12am    
Thanks for your reply..

I am also not sure that this will work but my client has put up this requirement.

rest all things i finished nw stuck on this point.

So u mean to say its impossible..?

Sanju
ZurdoDev 21-Jun-12 7:55am    
Look into querying Active Directory using LDAP.
Sanju TV 21-Jun-12 8:43am    
how to query into Active directory
i checked any sample u have ..
ZurdoDev 21-Jun-12 8:44am    
Samples are on the internet. Maybe start here, http://www.codeproject.com/Articles/18102/Howto-Almost-Everything-In-Active-Directory-via-C

XML
DirectoryEntry objDE = new DirectoryEntry("LDAP://XXXX", "UserLogin", "User Password");
            using (objDE)
            {
                DirectorySearcher objDSearcher = new DirectorySearcher();
                objDSearcher.SearchRoot = objDE;
                objDSearcher.PropertiesToLoad.Add("department");
                objDSearcher.PropertiesToLoad.Add("title");
                objDSearcher.PropertiesToLoad.Add("cn");

                objDSearcher.PropertiesToLoad.Add("SAMAccountName");
                objDSearcher.PropertiesToLoad.Add("givenname");

                objDSearcher.PropertiesToLoad.Add("sn");
                objDSearcher.PropertiesToLoad.Add("memberOf");

                objDSearcher.PropertiesToLoad.Add("department");
                objDSearcher.PropertiesToLoad.Add("title");

                objDSearcher.PropertiesToLoad.Add("postalCode");
                objDSearcher.PropertiesToLoad.Add("streetAddress");

                objDSearcher.PropertiesToLoad.Add("st");
                objDSearcher.PropertiesToLoad.Add("telephoneNumber");

                objDSearcher.PropertiesToLoad.Add("l");
                objDSearcher.PropertiesToLoad.Add("mail");

                objDSearcher.Filter = "(SAMAccountName=XXXXXXXXXX)";

                objDSearcher.SearchScope = SearchScope.Subtree;
                try
                {
                    SearchResultCollection result = objDSearcher.FindAll();
                    foreach (SearchResult sr in result)
                    {

                        Response.Write("ID:" + sr.Properties["SAMAccountName"][0].ToString() + "<br/>");
                        Response.Write("ID:" + sr.Properties["givenname"][0].ToString() + "<br/>");
                        Response.Write("ID:" + sr.Properties["cn"][0].ToString() + "<br/>");
                        Response.Write("Department:" + sr.Properties["Department"][0].ToString() + "<br/>");
                        Response.Write("title:" + sr.Properties["title"][0].ToString() + "<br/>");
                        Response.Write("------------------------------------------------------------------------<br/>");
                    }
                }
                catch (System.DirectoryServices.DirectoryServicesCOMException ex)
                {
                    Response.Write(ex.Message);
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                }
 
Share this answer
 
Comments
Sanju TV 3-Jul-12 8:51am    
Thank You
Friends,
Thanks for your help

i solved the problem i got solution from this below link.
My Solved Code



Thanks
Sanju
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900