i have to display all the Organisational units in my firm.
in the C# it is declared as
private void myInitializeComponent()
{
lvwColumnSorter = new ListViewColumnSorter();
this.listView_ad.ListViewItemSorter = lvwColumnSorter;
try
{
this._AdRootDSE = new DirectoryEntry("LDAP://rootDSE");
this._AdRoot = new DirectoryEntry("LDAP://" + (string)this._AdRootDSE.Properties["defaultNamingContext"].Value);
/*
foreach(string property in this._AdRoot.Properties.PropertyNames)
{
MessageBox.Show(property + " = " + this._AdRoot.Properties[property].Value);
}*/
TreeNode root = new TreeNode((string)this._AdRootDSE.Properties["defaultNamingContext"].Value,(int)AdImages.AdRoot,(int)AdImages.AdRoot);
root.Tag = this._AdRoot;
this.treeView_ad.Nodes.Clear();
this.treeView_ad.Nodes.Add(root);
}
catch
{
throw new Exception("Error connecting to AD");
}
}
and I have converted it to
vb.net as
Private Sub AdBrowserForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lvwColumnSorter = New ListViewColumnSorter
Me.listview_ad.ListViewItemSorter = lvwColumnSorter
Try
Me._AdRootDSE = New DirectoryEntry("LDAP://rootDSE")
Me._AdRoot = New DirectoryEntry("LDAP://" + Convert.ToString(Me._AdRootDSE.Properties("default NamingContext").Value))
'for each(string property in this._AdRoot.Properties.PropertyNames)
'{
'MessageBox.Show(property + " = " + this._AdRoot.Properties[property].Value);
'}*/
Dim root As TreeNode
root = New TreeNode(CType(Me._AdRootDSE.Properties("defaultNa mingContext").Value, String), CType(AdImages.AdRoot, Integer), CType(AdImages.AdRoot, Integer))
root.Tag = Me._AdRoot
Me.treeview_ad.Nodes.Clear()
Me.treeview_ad.Nodes.Add(root)
MsgBox("connection established")
Catch
Throw New Exception("Error connecting to AD")
End Try
which when i compile i get an error"Object reference not set to an object"
for the line
"lvwColumnSorter = New ListViewColumnSorter". when i comment this line , connection to the AD is established but it is not retirving any details.