JJKing
asked on
VB.Net access to the Active Directory
Hi
I have a VB.Net program that connects to AD using DirectoryServices. I can locate a user and retrieve properties for the account. My problem is that the search retrievs only certain properties using the PropertiesToLoad functionality, one of which is the users home directory, however if the home directory is blank for a given user then i get an 'Object reference not set to an instance of an object.' error when trying to put the property.value into a variable.
I have posted the portion of the code that is failing it fails on the _HomeDirPath = Results.GetDirectoryEntry( ).Properti es("homedi rectory"). Value.ToSt ring
It appears that the property is not loaded if blank is there a way i can check for the property not being loaded.
I have a VB.Net program that connects to AD using DirectoryServices. I can locate a user and retrieve properties for the account. My problem is that the search retrievs only certain properties using the PropertiesToLoad functionality, one of which is the users home directory, however if the home directory is blank for a given user then i get an 'Object reference not set to an instance of an object.' error when trying to put the property.value into a variable.
I have posted the portion of the code that is failing it fails on the _HomeDirPath = Results.GetDirectoryEntry(
It appears that the property is not loaded if blank is there a way i can check for the property not being loaded.
Try
DirectorySearcher()
_DSearch.Filter = "(&(objectClass=user) (SAMAccountName=" + UserID + "))"
_DSearch.PropertiesToLoad.Add("CN")
_DSearch.PropertiesToLoad.Add("distinguishedName")
_DSearch.PropertiesToLoad.Add("SN")
_DSearch.PropertiesToLoad.Add("homedirectory")
Dim Results As SearchResult = _DSearch.FindOne()
_CommonName = Results.GetDirectoryEntry().Properties("CN").Value
_DistinguishedName = Results.GetDirectoryEntry().Properties("distinguishedName").Value
_HomeDirPath = Results.GetDirectoryEntry().Properties("homedirectory").Value.ToString
If Not _HomeDirPath.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()) Then
_HomeDirPath &= System.IO.Path.DirectorySeparatorChar
End If
_SurName = Results.GetDirectoryEntry().Properties("SN").Value
_UserProfile = UserID
Catch ex As Exception
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER