Active Directory (namespace) programming Tip 1
Gotcha number one, when doing some domain coding you can easly get some domain information using the following code:
Dim MyDomain as Domain = Domain.GetCurrentDomain
‘To get the Domain Parent i.e. the parent of the domain in the Domain ‘
‘tree
Dim MyDomainParent as String = MyDomain.Parent
Pretty easy huh, however if you now try to get the parent for the domain that is ALREADY the parent domain i.e. you ask a root domain for its parent it will throw a Null exception.
So a easy work around:
If Not DomainToUse.Parent Is Nothing Then
Me.lblDomainParentValue.Text = DomainToUse.Parent.Name.ToString
ElseIf DomainToUse.Name = DomainToUse.Forest.RootDomain.Name Then
Me.lblDomainParentValue.Text = "This domain " & DomainToUse.Name & " is the root domain"
Else
Me.lblDomainParentValue.Text = "Is Unknown"
End If