Forums

Welcome to Forums Sign in | Join | Help
in Search

how to add entry into openLDAP using C#

Last post 02-02-2012, 9:57 PM by david. 19 replies.
Page 1 of 2 (20 items)   1 2 Next >
Sort Posts: Previous Next
  •  05-06-2006, 12:38 AM 1978

    how to add entry into openLDAP using C#

    Hi There

    I am using the code as follow and it is working fine

    http://ukamen.hp.infoseek.co.jp/Programming1/LDAP/

    but I can't find how I add an entry into openLdap? how can I create a group with their idea?

    Any one has some cule, please let me know, thanks

    Tony Dong itdong@hotmail.com
  •  09-29-2006, 11:15 PM 1992 in reply to 1978

    Re: how to add entry into openLDAP using C#

    With LDAP Client.Net this is done with the AddNewEntry method. See http://www.ldapservices.com/Products/LdapClient.Net/API/LdapServices.Ldap.Client.AddNewEntry.html for details and a sample.
  •  09-16-2009, 4:43 AM 2016 in reply to 1992

    Re: how to add entry into openLDAP using C# -- HELP NEEDED!! PLZ

    Hi,

    I am new to Active Directory domain and i have been given a task to download a file stored on an Active Directory server using LDAP protocol. I have searched the net but couldnt find anything related to file tranfer via ldap. My questions are as follows:

    1 - can files be stored on Active Directory along with users, printer and computers?
    2 - if yes then how can we retrieve/download the file from the AD server? (prefferably using C#).
    3 - does file transfer to/from Active Directory only involves LDAP or are there other factors to consider too?

    please point me in the right direction, Any help will be greatly appreciated.

    Thank & Regards,
    Jahangir
    jahangir.raza.shah@hotmail.com
  •  05-17-2010, 4:15 AM 2018 in reply to 1992

    Re: how to add entry into openLDAP using C#

    0

    I'm trying to create a new user record into OpenLDAP with object classes person and uidObject. The problem seems to be that with System.DirectoryServices.DirectoryEntry I've found only a way to add a new entry with one object class, but not a way to add multiple object classes.

    This C# code

    DirectoryEntry nRoot = new DirectoryEntry(path);
    nRoot
    .AuthenticationType = AuthenticationTypes.None;
    nRoot
    .Username = username;
    nRoot
    .Password = pwd;

    try
    {
       
    DirectoryEntry newUser = nRoot.Children.Add("CN=" + "test", "person");
        newUser
    .Properties["cn"].Add("test");
        newUser
    .Properties["sn"].Add("test");
        newUser
    .Properties["objectClass"].Add("uidObject"); // this doesnt't make a difference
        newUser
    .Properties["uid"].Add("testlogin"); // this causes trouble
        newUser
    .CommitChanges();
    }
    catch (COMException ex)
    {
       
    Console.WriteLine(ex.ErrorCode + "\t" + ex.Message);
    }
    ======================
    *** Augmentation | *** Enlargement
  •  05-20-2010, 6:20 PM 2021 in reply to 2018

    Re: how to add entry into openLDAP using C#

    It turns out that you can add object classes after the entry has first been stored to LDAP and fetched again. So, with a simple change it works just fine!

    DirectoryEntry newUser = nRoot.Children.Add("CN=" + "test", "person");
    newUser
    .Properties["cn"].Add("test");
    newUser
    .Properties["sn"].Add("test");
    newUser
    .CommitChanges();

    newUser
    .RefreshCache();
    newUser
    .Properties["objectClass"].Add("uidObject");
    newUser
    .Properties["uid"].Add("testlogin");
    newUser
    .CommitChanges();
    _______________________________________________________
    SEO Agency
    SEO Newcastle

  •  05-23-2010, 10:10 PM 2022 in reply to 1978

    Re: how to add entry into openLDAP using C#

    DirectoryEntry newUser = nRoot.Children.Add("CN=" + "test", "person");
    newUser
    .Properties["cn"].Add("test");
    newUser
    .Properties["sn"].Add("test");
    newUser
    .CommitChanges();

    newUser
    .RefreshCache();
    newUser
    .Properties["objectClass"].Add("uidObject");
    newUser
    .Properties["uid"].Add("testlogin");
    newUser
    .CommitChanges();
    =====================
    SEO Link Building | Link Building Company

  •  05-25-2010, 2:21 AM 2024 in reply to 1978

    Re: how to add entry into openLDAP using C#

    Before you update any user information it is probably a good idea to find out if they actually exist in the Active Directory.

    public bool UserExists(string username)
    {
       DirectoryEntry de = GetDirectoryEntry();
       DirectorySearcher deSearch = new DirectorySearcher();

       deSearch.SearchRoot = de;
       deSearch.Filter = "(&(objectClass=user) (cn=" + username + "))";

       SearchResultCollection results = deSearch.FindAll();

       return results.Count > 0;
    }

    private String FindName(String userAccount)
    {
       DirectoryEntry entry = GetDirectoryEntry();
       String account = userAccount.Replace(@"Domain\", "");

       try
       {
          DirectorySearcher search = new DirectorySearcher(entry);
          search.Filter = "(SAMAccountName=" + account + ")";
          search.PropertiesToLoad.Add("displayName");

          SearchResult result = search.FindOne();

          if (result != null)
          {
             return
    result.Properties["displayname"][0].ToString();
          }
          else
          {
             return "Unknown User";
          }
       }
       catch (Exception ex)
       {
          string debug = ex.Message;

          return "";
       }
    }

    ============================

    SEO Costs |SEO Prices


  •  05-26-2010, 10:49 PM 2026 in reply to 1978

    Re: how to add entry into openLDAP using C#

    // Check out LDAP daemon(slapd) is running.

    [root@uchukamen init.d]# ps ax | grep slapd
    24693 ? Ssl 0:00 /usr/sbin/slapd -u ldap -h ldap:///
    24734 pts/1 S+ 0:00 grep slapd

    // Add LDAP entries by ldapadd command.
    [root@uchukamen ldap]# ldapadd -x -D 'cn=Manager,dc=uchukamen,dc=com' -W -f /root/Desktop/uchukamen.ldif
    Enter LDAP Password: secret
    adding new entry "dc=uchukamen,dc=com"

    adding new entry "cn=Manager,dc=uchukamen,dc=com"

    // Search LDAP entries by ldapearch command.
    [root@uchukamen ldap]# ldapsearch -x -b 'dc=uchukamen,dc=com' -s sub '(cn=*)'
    # extended LDIF
    #
    # LDAPv3
    # base <dc=uchukamen,dc=com> with scope sub
    # filter: (cn=*)
    # requesting: ALL
    #

    # Manager, uchukamen.com
    dn: cn=Manager,dc=uchukamen,dc=com
    objectClass: organizationalRole
    cn: Manager

    # search result
    search: 2
    result: 0 Success

    # numResponses: 2
    # numEntries: 1
    [root@uchukamen ldap]#

    // Now OpenLDAP is up and running!

    ===========

    Organic Seo |Christian Seo


  •  06-17-2010, 8:07 PM 2031 in reply to 1978

    Re: how to add entry into openLDAP using C#

    Modify User Information
    public void ModifyUser(string userDisplayName, string username, string password)
    {
       DirectoryEntry de = GetDirectoryEntry();
       de.Username = username;
       de.Password = password;

       DirectorySearcher ds = new DirectorySearcher(de);
       ds.Filter = ("(&(objectclass=user)(objectcategory=person)
                   (displayname="
    + userDisplayName + "))");

       ds.SearchScope = SearchScope.Subtree;

       SearchResult results = ds.FindOne();

       if (results != null)
       {
          try
          {
             DirectoryEntry updateEntry = results.GetDirectoryEntry();
             updateEntry.Properties["department"].Value = "555";
             updateEntry.CommitChanges();
             updateEntry.Close();
          }
          catch (Exception ex)
          {
             tbError.Text = ex.ToString();
          }
       }

       de.Close();
    }

    =================


    Sports Nutrition | Sports Supplements



  •  06-19-2010, 3:40 AM 2033 in reply to 1978

    Re: how to add entry into openLDAP using C#

    public bool UserExists(string username)
    {
       DirectoryEntry de = GetDirectoryEntry();
       DirectorySearcher deSearch = new DirectorySearcher();

       deSearch.SearchRoot = de;
       deSearch.Filter = "(&(objectClass=user) (cn=" + username + "))";

       SearchResultCollection results = deSearch.FindAll();

       return results.Count > 0;
    }

    private String FindName(String userAccount)
    {
       DirectoryEntry entry = GetDirectoryEntry();
       String account = userAccount.Replace(@"Domain\", "");

       try
       {
          DirectorySearcher search = new DirectorySearcher(entry);
          search.Filter = "(SAMAccountName=" + account + ")";
          search.PropertiesToLoad.Add("displayName");

          SearchResult result = search.FindOne();

          if (result != null)
          {
             return
    result.Properties["displayname"][0].ToString();
          }
          else
          {
             return "Unknown User";
          }
       }
       catch (Exception ex)
       {
          string debug = ex.Message;

          return "";
       }
    }

    The form I created has 2 textboxes (Username & Password) and a submit button. When the button is clicked all the events are fired and if everything checks out the user is updated in Active Directory.

    ================


    Search Engine Optimisation UK | Link Building

  •  09-01-2010, 10:13 AM 2042 in reply to 2033

    Re: how to add entry into openLDAP using C#


    I am new to Active Directory domain and i have been given a task to download a file stored on an Active Directory server using LDAP protocol. I have searched the net but couldnt find anything related to file tranfer via ldap.

    --------------------
    *** Enlargement Cream
    *** Enlargement Pills
  •  09-06-2010, 9:53 PM 2044 in reply to 2042

    Re: how to add entry into openLDAP using C#

    does file transfer to/from Active Directory only involves LDAP or are there other factors to consider too?

    ------------------
    Adios Slimming Pills
    Airfix Models
  •  09-12-2010, 9:48 AM 2046 in reply to 1978

    Re: how to add entry into openLDAP using C#

    I have searched the net but couldnt find anything related to file tranfer via ldap.


    --------------------------
    Seo Glasgow
    link building
  •  09-17-2010, 6:50 AM 2048 in reply to 2046

    Re: how to add entry into openLDAP using C#

    DirectoryEntry newUser = nRoot.Children.Add("CN=" + "test", "person");
    newUser
    .Properties["cn"].Add("test");
    newUser
    .Properties["sn"].Add("test");
    newUser
    .CommitChanges();

    newUser
    .RefreshCache();
    newUser
    .Properties["objectClass"].Add("uidObject");
    newUser
    .Properties["uid"].Add("testlogin");
    newUser
    .CommitChanges();


    ____________________________________________________________
    Ben 10 Games
    Ben 10

  •  09-19-2010, 7:56 PM 2052 in reply to 2048

    Re: how to add entry into openLDAP using C#

    this is really helpful guys. thanx!

    unsecured bad credit loan
Page 1 of 2 (20 items)   1 2 Next >
View as RSS news feed in XML