Difficult one...Active Directory + XML...

Posted on 2007-03-20
Last Modified: 2013-11-07
I read from AD and The CN (commonName) has a property that if i get its value
i get it in XML format.
I'm lookin for some way to enter the nodes and retrieve the value.
My code (to get other properties valus) are:
DirectoryEntry root = new DirectoryEntry(
              "User", "Password", AuthenticationTypes.ServerBind);

            DirectorySearcher search = new DirectorySearcher(root);
            search.Filter = "(&(objectClass=user))";
            SearchResult result;
            SearchResultCollection resultCol = search.FindAll();
            string[] allUsers = new string[resultCol.Count];
            if (resultCol != null)
                     for (int counter = 0; counter < resultCol.Count; counter++)
                    result = resultCol[counter];
                    if (result.Properties.Contains("ID"))
                        allUsers[counter] = ((string)result.Properties["ID"][0]);                                      
                        Console.WriteLine("Value : " + allUsers[counter]);
and i get all the values of the ID propert.
Now, there is a property - which its value is in XML :
   <way> SMS </way>
The property name is : " Delivery ".
(if i try to retrieve Delivery value - i get an XML result.
I need to get only the value ---  SMS
Is it possible?
Question by:udir
  • 4
LVL 16

Accepted Solution

jimbobmcgee earned 500 total points
ID: 18759644
Does it always return valid XML?  And does it return it as a string?
If so, something like:

    // ...
    object deliveryValue = result.Properties["Delivery"];
    string wayValue = null;
    if (deliveryValue != null)
        XmlDocument xml = new XmlDocument();
        XmlNode wayNode = xml.SelectSingleNode("//names/way");
        if (wayNode != null) wayValue = wayNode.Value;
    // ...



Author Comment

ID: 18762300
Thanks for the reply.
It looks like the right way  (:
the problem is that i get nulls.
(i also changed the line to - object deliveryValue = ((string)result.Properties["ladpcInfodelivery"][0]);  )

Maybe the single Node Method has a wrong path?
the real pass that i wrote in the code in order to get to the Node is : (above i just gave an example)
XmlNode Nodename = xml.SelectSingleNode("//ArrayofApp/App/Name/Modules/Module/Name/DeliveryMethods/DeliveryMethod/Name");
and the XML looks like this (when i get the property Value)
Value : <ArrayOfApp>

Am i missing somthing?

Author Comment

ID: 18762303
Oh, and i need to get the only the Name value - " EMail "

Author Comment

ID: 18762624
or SMS

Author Comment

ID: 18763015
OK, let me sumerize the problem so far:
1)  If i write as you wrote :  object deliveryValue = result.Properties["Delivery"];
      i get an error :  Data at the root level is invalid. Line 1, position 1
      at the line :  xml.LoadXml(deliveryValue.ToString());
 (which i understand is becuase the property return not a valid XML but a string (as you can see in the file above - it really begins with " Value : <ArrayOfApp>...........

2)  If i write as I wrote :  object deliveryValue = ((string)result.Properties["ladpcInfodelivery"][0]);
      i get nulls - " wayNode " is null (maybe somthing with the root)

How can it be solved (dosn't metter which way)

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Chat Room 1 28
As soon as i click a button on the form,it mnimises. 11 20
VB.NET HttpWebRequest 12 32
Saveas need to save a copy 16 11
It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now