| vini on Apr 2, 2007 at 10:22:51 PM Actually i want to display the all the organisational units that are available in our firm by connecting to AD.
This is the code that is used in c# for that:
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");
}
}
i have converted to vb.net as follows:
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("defaultNamingContext").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("defaultNamingContext").Value, String), CType(AdImages.AdRoot, Integer), CType(AdImages.AdRoot, Integer))
root = New TreeNode(Convert.ToString(Me._AdRootDSE.Properties("defaultNamingContext").Value), Convert.ToInt32(AdImages.AdRoot), Convert.ToInt32(AdImages.AdRoot))
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
I have declared the ListViewColumnSorter in Class. When i run it produces the result in C#(conection to the AD is established and all the units are also fetched) but in VB.NEt produces a runtime error "Object reference not set to an object". when i comment the first line "lvwColumnSorter = New ListViewColumnSorter" the connection to the AD is established but nothing is retrived from it :-(
|