473,406 Members | 2,954 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,406 software developers and data experts.

Active directory in c#

fayazmd
41
Hi,

I want to get full name and city from outlook properties. For this i used active directory. I am getting fullname but unable to get city. Here is my code

System.DirectoryServices.DirectoryEntry ADEntry = new System.DirectoryServices.DirectoryEntry("WinNT://Domain/" + userid);
string FullName = ADEntry.Properties["FullName"].Value.ToString();

Any help appreciated.

And i want to know his out of office status also.

I am working in asp.net 2.0, C#.
May 20 '08 #1
6 5570
Plater
7,872 Expert 4TB
How does ActiveDirectory = Outlook?
May 21 '08 #2
arggg
91
I believe he means he has Outlook setup to use AD for information.

Here is what I have in my C# program

Expand|Select|Wrap|Line Numbers
  1.             try
  2.             {
  3.                 object obj = entry.NativeObject;
  4.                 DirectorySearcher search = new DirectorySearcher(entry);
  5.                 search.Filter = "(sAMAccountName=" + username + ")";
  6. //Get full name
  7.                 search.PropertiesToLoad.Add("cn");
  8. //Get account name
  9.                 search.PropertiesToLoad.Add("sAMAccountName");
  10. //Get title
  11.                 search.PropertiesToLoad.Add("title");
  12.                 SearchResult result = search.FindOne();
  13.                 if (null == result)
  14.                 {
  15.                     return false;
  16.                 }
  17.                 //update the new path to the user
  18.                 _path = result.Path;
  19.                 _filterAttribute = (string)result.Properties["cn"][0];
  20.  
  21.                 //Set the session variables.
  22.                 Login._userInfo["Name"] = (string)result.Properties["cn"][0];
  23.                 Login._userInfo["Account"] = (string)result.Properties["sAMAccountName"][0];
  24.                 Login._userInfo["title"] = (string)result.Properties["title"][0];
  25.  
  26.             }
  27.             catch (System.Exception ex)
  28.             {
  29.                 throw new System.Exception(ex.Message);
  30.             }
  31.  
All you would need to do is add search.PropertiesToLoad.Add("city");
May 21 '08 #3
fayazmd
41
My apologies for unclear description.

Here is the thing what exactly i want.

I need to get all the members of DistributionList and details of employee based on his id. For this, I am using LDAP. I am getting few things. Here is my code.

DirectorySearcher search;
DirectoryEntry entry;
SearchResult result;
String mailid = "";
bool flag = false;


entry = new DirectoryEntry("LDAP://Domain", "uid", "pwd");

search = new DirectorySearcher(entry);
search.Filter = "CN=DL Name";
int i = search.Filter.Length;

string str = "";
foreach (SearchResult AdObj in search.FindAll())
{

foreach (String objName in AdObj.GetDirectoryEntry().Properties["member"])
{
//str += Convert.ToString(objName) + "<Br>";
int selIndex = objName.IndexOf("CN=") + 3;
int selEnd = objName.IndexOf(",OU") - 3;
//str1 += objName.Substring(selIndex, selEnd).Replace("\\", "") + "<BR>";

DirectorySearcher dsSearch = new DirectorySearcher(entry);
dsSearch.Filter = "CN=" + objName.Substring(selIndex, selEnd).Replace("\\", "");
foreach (SearchResult rs in dsSearch.FindAll())
{
str += "&lt;><font face='calibri' color='#2266aa' size=2>" + Convert.ToString(rs.GetDirectoryEntry().Properties["mail"].Value) + "|" + Convert.ToString(rs.GetDirectoryEntry().Properties["displayName"].Value) + "|" + Convert.ToString(rs.GetDirectoryEntry().Properties["sAMAccountName"].Value) + "|" + Convert.ToString(rs.GetDirectoryEntry().Properties["department"].Value) + "|" + /*Convert.ToString(rs.GetDirectoryEntry().Propertie s["memberOf"].Value)+ */ Convert.ToString(rs.GetDirectoryEntry().Properties["l"].Value) + "&lt;></p>";
}
}
}
// Response.Write("&lt;BR>" + str + "&lt;Br>" + str1 + "&lt;BR>");
Response.Write(str + "&lt;BR>");


If i am passing one DL its working fine. But if i am changing DL name to other existing DL its not displaying. Its coming out of foreach loop from dsSearch.FindAll().

Where i am going wrong. And i need to get his department also.
May 23 '08 #4
Plater
7,872 Expert 4TB
Can you use anything discussed in this thread to help you out?
http://bytes.com/forum/thread796552.html
May 23 '08 #5
fayazmd
41
Can you use anything discussed in this thread to help you out?
http://bytes.com/forum/thread796552.html
Thanks a lot. Now i can pull active direcory info.

But one more thing i need to get one's out of office status. How can get this through c#.
May 24 '08 #6
Plater
7,872 Expert 4TB
Thanks a lot. Now i can pull active direcory info.

But one more thing i need to get one's out of office status. How can get this through c#.
Is that kept track of in the active directory system?

Question split off to here:
http://bytes.com/forum/thread796936.html
May 27 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jay Chan | last post by:
We have just installed a SQL Server 2000 (SP 3A) onto a computer that has Windows-2003 Server on it. Now, we cannot get access to that database server from other computers. Seem like this may be an...
0
by: microsoft | last post by:
Hi People, when I try to modify an active directory user programatically, I receive the following exception: The server is unwilling to process the request Reading the microsoft web site, I...
9
by: Mario Rodriguez | last post by:
Hi people. I have a problem adding users to Win2003 active directory programatically. When I execute my app throws the following exception: .................The specified directory service...
4
by: ASGMikeG | last post by:
Hi, How do I find the user object for the current user in Active Directory i.e. the user running my program ? Regards Michael
1
by: Andrew | last post by:
Hey all, Working on revamping our Intranet here and making use of the LDPA, Active Directory, Directory Services, etc. that .Net provides. I am still fairly new on this subject, so the problem...
6
by: Leo_Surf | last post by:
Hello, I need your help adding user in Active Directory from ASP.net website. Could any one provide me the complete code for the html page. As this is my curriculam project and I dont have any...
1
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 =...
10
by: Hriday | last post by:
Hi there, Please help me..It is urgent This is Hriday, working on windows authentication with Active Directory... My requirment is when a user sends a request to my web Applicatoin I want to...
0
by: RTT | last post by:
here is my current situation. I develop a program on my computer's localhost. From there i contact Active directory succesfull using a connectionstring like:...
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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
agi2029
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,...
0
isladogs
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...

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.