I have a list for personel.

I want add new user to AD when adding a new item in personel list.

I use this code but don't created user

private SPUser CreateUser(string strLoginName, string strEMail, 
string strName, string strNotes, string strSiteURL)
SPUser spReturn = null;
SPSite spSite = null;
SPWeb spWeb = null;

    //Open the SharePoint site
    spSite     = new SPSite(strSiteURL);
    spWeb     = spSite.OpenWeb();

    //Assign role and add user to site
    SPRoleAssignment spRoleAssignment = 
        new SPRoleAssignment(strLoginName, strEMail, strName, strNotes);
    //Using Contribute, might need high access
    SPRoleDefinition spSPRoleDefinition = 


    //Update site
    spReturn = spWeb.AllUsers[strLoginName];

return spReturn;


The following worked for me:

 SPUser user = spWeb.EnsureUser(strLoginName);
 SPRoleAssignment spRoleAssignment = 
 new SPRoleAssignment(user);
  • 1
    We need more information to answer your question. Are you saying you want to add an item to SharePoint list and have that create a user in AD? Or are you referring to user profile synchronization? – SPDoctor Feb 2 '12 at 12:09
  • 1
    Or maybe hes looking for a webpart to manage AD? adselfservice.codeplex.com – Kit Menke Feb 2 '12 at 15:46
  • Yes , I want created a webpart for manage AD. – ar.gorgin Feb 3 '12 at 5:19

first you need Event Receiver to handle ItemAdded event, something like this:


        public override void ItemAdded(SPItemEventProperties properties)

           //Your Code to Add User To AD


you can read current item with this line:

SPListItem personelItem = properties.ListItem;

then you need to read personelItem fields (for username and other info you need to add to AD) and then you must write your code to Add User To Active Directory

| improve this answer | |
  • Thanks, I need Event Receiver to handle ItemAdded event and then i want add user to AD . but i don't use this code in sharepoint. – ar.gorgin Feb 3 '12 at 5:33

it seems to sync the items in the sharepoint list as new users to the AD. It is possible.

| improve this answer | |
  • I can add a new user to manually? – ar.gorgin Feb 2 '12 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.