Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Use  .PropertiesToLoad.Add("nvdPolicy")

Posted on 2010-08-12
7
Medium Priority
?
544 Views
Last Modified: 2013-11-07
I have a path in active directory and need to get some values for that path with .net 2.0.  I can see these values with adsi edit, but would like to populate a combobox with them.

Here is what I have, but it's not working.  What am I missing?
  Dim strSoftType As String = ""
        If RadioButton2.Checked = True Then
            strSoftType = "OU=Software,"
        ElseIf RadioButton1.Checked = True Then
            strSoftType = "OU=Softserv,"
        End If
        Dim SoftName = "OU=" & ComboBox1.Text.Trim & ","
        Dim strTypeInstall As String = "CN=" & ComboBox2.Text.Trim & ","
        ComboBox3.Items.Clear()

        Dim strSoftwareLoc, strSoftwareName As DirectoryEntry
       


        Dim strResult As SearchResult
        Dim strSoftwareList As String = ""
        strSoftwareLoc = New DirectoryEntry("LDAP://" & strTypeInstall & SoftName & strSoftType & "OU=Radia,OU=Applications,DC=mydomain,DC=com")
        Dim strSearch As New DirectorySearcher(strSoftwareLoc)

        With strSearch
            .SearchScope = SearchScope.Subtree
            .PropertiesToLoad.Add("nvdPolicy")
            .PropertiesToLoad.Add("nvdPolicyOverride")
        End With

        strSearch.SearchRoot = strSoftwareLoc

        For Each strResult In strSearch.

            Dim title As DirectoryEntry
            title = strResult.GetDirectoryEntry.Properties("nvdPolicy").Value '***************** I FAIL HERE




            ComboBox3.Items.Add(title)    'add to combobox and remove OU=

        Next
0
Comment
Question by:chadmanvb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 33429361
for better practice u first want to check if property is exists, for instance:

    Dim title As DirectoryEntry
dim objVal  as object
objVal = strResult.GetDirectoryEntry.Properties("nvdPolicy")
if not objVal  = nothing then
            title = objVal.Value
else
'property nvdPolicy doesn't exists
end if
0
 

Author Comment

by:chadmanvb
ID: 33429809
I get this error:
Operator '=' is not defined for type 'PropertyValueCollection' and 'Nothing'.

on line: if not objVal  = nothing then

any ideas?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 33429898
try debug your code to till this line:
objVal = strResult.GetDirectoryEntry.Properties("nvdPolicy")

what is the value of objVal?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 42

Accepted Solution

by:
sedgwick earned 2000 total points
ID: 33430026
try the following:

With strSearch
            .SearchScope = SearchScope.Subtree
            .PropertiesToLoad.Add("nvdPolicy")
            .PropertiesToLoad.Add("nvdPolicyOverride")
        End With

        strSearch.SearchRoot = strSoftwareLoc

        For Each strResult In strSearch.FindAll()
            For Each item In strResult.GetDirectoryEntry().Properties("nvdPolicy")

            Next
 For Each item In strResult.GetDirectoryEntry().Properties("nvdPolicyOverride")

            Next
        Next
0
 

Author Comment

by:chadmanvb
ID: 33430550
Looks like I am still getting the same error I originally had:

Unable to cast object of type 'System.String' to type 'System.DirectoryServices.DirectoryEntry'.

 With strSearch
            .SearchScope = SearchScope.Subtree
            .PropertiesToLoad.Add("nvdPolicy")
            .PropertiesToLoad.Add("nvdPolicyOverride")
        End With

        strSearch.SearchRoot = strSoftwareLoc

        For Each strResult In strSearch.FindAll()
            Dim title As DirectoryEntry
            For Each item In strResult.GetDirectoryEntry().Properties("nvdPolicy")


                Dim objVal As Object
                objVal = strResult.GetDirectoryEntry.Properties("nvdPolicy")

                title = objVal.Value  '*******************fails here


            Next

            For Each item In strResult.GetDirectoryEntry().Properties("nvdPolicyOverride")


            Next
            ComboBox3.Items.Add(title)    'add to combobox and remove OU=
        Next
0
 

Author Comment

by:chadmanvb
ID: 33431171
When I change the variable to Dim strAttributeValue As Object

It works fine.  Can a directory value not be converted to a string?
0
 

Author Closing Comment

by:chadmanvb
ID: 33435944
Thanks, that's working.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question