EDN Admin
Well-known member
Hey Guys,
i am trying to add a user to list of active directory groups. i am getting the "object reference not set to an instance of an object" error, when below line executes, please help.
<span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small <font face="Consolas" size="2" color="#2b91af" style="font-family:Consolas; color:#2b91af; font-size:x-small
DirectoryEntry
</font>
<span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; font-size:x-small group = result.GetDirectoryEntry();
see below for whole code block.
<div style="color:Black;background-color:White; <pre>
{ <span style="color:Green; //start if checklistbox1
<span style="color:Blue; string selectedgroup = <span style="color:#A31515; ""; <span style="color:Blue; for (<span style="color:Blue; int i = 0; i <= checkedListBox1.CheckedItems.Count - 1; i++)
{
selectedgroup = checkedListBox1.CheckedItems.ToString() + <span style="color:#A31515; "n";
MessageBox.Show(selectedgroup);
<span style="color:Green; //START ADD GROUP FUNCTION
<span style="color:Green; //deUser - newuserdn
System.DirectoryServices.DirectoryEntry RootDSE1 = <span style="color:Blue; new System.DirectoryServices.DirectoryEntry(<span style="color:#A31515; "LDAP://RootDSE1");
<span style="color:Blue; string DomainDistinguishedName1 = RootDSE.Properties[<span style="color:#A31515; "defaultNamingContext"].Value.ToString();
System.DirectoryServices.DirectoryEntry child1 = <span style="color:Blue; new System.DirectoryServices.DirectoryEntry(<span style="color:#A31515; "LDAP://" + DomainDistinguishedName);
DirectorySearcher deSearch = <span style="color:Blue; new DirectorySearcher(child1);
deSearch.SearchRoot = child1;
deSearch.Filter = <span style="color:#A31515; "(&(objectClass=group) (cn=" + selectedgroup +<span style="color:#A31515; "))";
SearchResult result = <span style="color:Blue; null;
result = deSearch.FindOne();
DirectoryEntry <span style="color:Blue; group = result.GetDirectoryEntry();
<span style="color:Blue; group.Invoke(<span style="color:#A31515; "Add", <span style="color:Blue; new <span style="color:Blue; object[] { newUser.Path.ToString() });
<span style="color:Blue; group.Close();
<span style="color:Green; //END ADD GROUP FUNCTION
<span style="color:Green; //
}
} <span style="color:Green; //end if checklistbox1
[/code]
View the full article
i am trying to add a user to list of active directory groups. i am getting the "object reference not set to an instance of an object" error, when below line executes, please help.
<span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small <font face="Consolas" size="2" color="#2b91af" style="font-family:Consolas; color:#2b91af; font-size:x-small
DirectoryEntry
</font>
<span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; font-size:x-small group = result.GetDirectoryEntry();
see below for whole code block.
<div style="color:Black;background-color:White; <pre>
{ <span style="color:Green; //start if checklistbox1
<span style="color:Blue; string selectedgroup = <span style="color:#A31515; ""; <span style="color:Blue; for (<span style="color:Blue; int i = 0; i <= checkedListBox1.CheckedItems.Count - 1; i++)
{
selectedgroup = checkedListBox1.CheckedItems.ToString() + <span style="color:#A31515; "n";
MessageBox.Show(selectedgroup);
<span style="color:Green; //START ADD GROUP FUNCTION
<span style="color:Green; //deUser - newuserdn
System.DirectoryServices.DirectoryEntry RootDSE1 = <span style="color:Blue; new System.DirectoryServices.DirectoryEntry(<span style="color:#A31515; "LDAP://RootDSE1");
<span style="color:Blue; string DomainDistinguishedName1 = RootDSE.Properties[<span style="color:#A31515; "defaultNamingContext"].Value.ToString();
System.DirectoryServices.DirectoryEntry child1 = <span style="color:Blue; new System.DirectoryServices.DirectoryEntry(<span style="color:#A31515; "LDAP://" + DomainDistinguishedName);
DirectorySearcher deSearch = <span style="color:Blue; new DirectorySearcher(child1);
deSearch.SearchRoot = child1;
deSearch.Filter = <span style="color:#A31515; "(&(objectClass=group) (cn=" + selectedgroup +<span style="color:#A31515; "))";
SearchResult result = <span style="color:Blue; null;
result = deSearch.FindOne();
DirectoryEntry <span style="color:Blue; group = result.GetDirectoryEntry();
<span style="color:Blue; group.Invoke(<span style="color:#A31515; "Add", <span style="color:Blue; new <span style="color:Blue; object[] { newUser.Path.ToString() });
<span style="color:Blue; group.Close();
<span style="color:Green; //END ADD GROUP FUNCTION
<span style="color:Green; //
}
} <span style="color:Green; //end if checklistbox1
[/code]
View the full article