Click here to Skip to main content
15,169,285 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,

i am try to add user to activedirectory group in windows server.that users call from share point list.i am get the items from share point list successfully.but i am trying to add users to active directory distribution group.some exception and errors came.so please help me to find the solution


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//SharePoint namespace
using Microsoft.SharePoint.Client;
using System.Net;
using EnCryptDecrypt;
using System.Configuration;
using System.Security.Cryptography;
using System.IO;
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            string key = "a text phrase";
            string abc = ConfigurationSettings.AppSettings[0];
            string cmc = ConfigurationSettings.AppSettings[1];
            // string cmc = "HjMoHs9EMx2NDTdkv4QDUg==";

            // string abc = "s1SYwK14I+PvRZBZtWdDw==";
            ClientContext clientContext = new ClientContext("http://xxxxxxxx");
            NetworkCredential cred = new NetworkCredential();
            //string encrypt = encrypt(abc, key);
            cred.UserName = abc;

            string decryptedText = CryptorEngine.Decrypt(cmc, key);

            cred.Password = decryptedText;
            clientContext.Credentials = cred;
            List list = clientContext.Web.Lists.GetByTitle("account");
            CamlQuery camlQuery = new CamlQuery();
            camlQuery.ViewXml = "<View/>";
            ListItemCollection listItems = list.GetItems(camlQuery);
            clientContext.Load(list); clientContext.Load(listItems);
            clientContext.ExecuteQuery();
            foreach (ListItem listItem in listItems)
                Console.WriteLine("\nTitle: {0}", listItem["Title"]);
          
            DirectoryEntry directoryEntry;
            try
            {
                directoryEntry = new DirectoryEntry("LDAP://CN=IT,CN=Users, DC=dev, DC=com");
                directoryEntry.RefreshCache();
                DirectoryEntry groupContact = new DirectoryEntry("LDAP://CN=,CN=Users, DC=dev, DC=com");
                directoryEntry.Properties["member"].Add(groupContact.Properties);
                directoryEntry.CommitChanges();
            }
            catch (Exception e)
            {
                 var msg = e.Message.ToString();
                throw;
            }
            Console.ReadLine();
        }

       
    }
    
}
Posted
Updated 6-May-13 7:29am
v2
Comments
[no name] 6-May-13 12:14pm
   
"exception and errors came" and we are supposed to guess what the exception that you got was and what the errors are?

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