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

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 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);
            foreach (ListItem listItem in listItems)
                Console.WriteLine("\nTitle: {0}", listItem["Title"]);
            DirectoryEntry directoryEntry;
                directoryEntry = new DirectoryEntry("LDAP://CN=IT,CN=Users, DC=dev, DC=com");
                DirectoryEntry groupContact = new DirectoryEntry("LDAP://CN=,CN=Users, DC=dev, DC=com");
            catch (Exception e)
                 var msg = e.Message.ToString();

Updated 6-May-13 6:29am
[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