Active directory in c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fayazmd
    New Member
    • Jul 2007
    • 41

    Active directory in c#

    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.Director yServices.Direc toryEntry ADEntry = new System.Director yServices.Direc toryEntry("WinN T://Domain/" + userid);
    string FullName = ADEntry.Propert ies["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#.
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    How does ActiveDirectory = Outlook?

    Comment

    • arggg
      New Member
      • Mar 2008
      • 91

      #3
      I believe he means he has Outlook setup to use AD for information.

      Here is what I have in my C# program

      Code:
      			try
      			{
      				object obj = entry.NativeObject;
      				DirectorySearcher search = new DirectorySearcher(entry);
      				search.Filter = "(sAMAccountName=" + username + ")";
      //Get full name
      				search.PropertiesToLoad.Add("cn");
      //Get account name
      				search.PropertiesToLoad.Add("sAMAccountName");
      //Get title
      				search.PropertiesToLoad.Add("title");
      				SearchResult result = search.FindOne();
      				if (null == result)
      				{
      					return false;
      				}
      				//update the new path to the user
      				_path = result.Path;
      				_filterAttribute = (string)result.Properties["cn"][0];
      
      				//Set the session variables.
      				Login._userInfo["Name"] = (string)result.Properties["cn"][0];
      				Login._userInfo["Account"] = (string)result.Properties["sAMAccountName"][0];
      				Login._userInfo["title"] = (string)result.Properties["title"][0];
      				
      			}
      			catch (System.Exception ex)
      			{
      				throw new System.Exception(ex.Message);
      			}
      All you would need to do is add search.Properti esToLoad.Add("c ity");

      Comment

      • fayazmd
        New Member
        • Jul 2007
        • 41

        #4
        My apologies for unclear description.

        Here is the thing what exactly i want.

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

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


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

        search = new DirectorySearch er(entry);
        search.Filter = "CN=DL Name";
        int i = search.Filter.L ength;

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

        foreach (String objName in AdObj.GetDirect oryEntry().Prop erties["member"])
        {
        //str += Convert.ToStrin g(objName) + "<Br>";
        int selIndex = objName.IndexOf ("CN=") + 3;
        int selEnd = objName.IndexOf (",OU") - 3;
        //str1 += objName.Substri ng(selIndex, selEnd).Replace ("\\", "") + "<BR>";

        DirectorySearch er dsSearch = new DirectorySearch er(entry);
        dsSearch.Filter = "CN=" + objName.Substri ng(selIndex, selEnd).Replace ("\\", "");
        foreach (SearchResult rs in dsSearch.FindAl l())
        {
        str += "&lt;><font face='calibri' color='#2266aa' size=2>" + Convert.ToStrin g(rs.GetDirecto ryEntry().Prope rties["mail"].Value) + "|" + Convert.ToStrin g(rs.GetDirecto ryEntry().Prope rties["displayNam e"].Value) + "|" + Convert.ToStrin g(rs.GetDirecto ryEntry().Prope rties["sAMAccountName "].Value) + "|" + Convert.ToStrin g(rs.GetDirecto ryEntry().Prope rties["department "].Value) + "|" + /*Convert.ToStri ng(rs.GetDirect oryEntry().Prop erties["memberOf"].Value)+ */ Convert.ToStrin g(rs.GetDirecto ryEntry().Prope rties["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.FindAl l().

        Where i am going wrong. And i need to get his department also.

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          Can you use anything discussed in this thread to help you out?

          Comment

          • fayazmd
            New Member
            • Jul 2007
            • 41

            #6
            Originally posted by Plater
            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#.

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              Originally posted by fayazmd
              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:

              Comment

              Working...