Team LiB
Previous Section Next Section

Directory Caching

By default, ADSI/System.DirectoryServices uses caching when you call the first method or use the first property of an object. You can disable this by setting DirectoryEntry.UsePropertyCache to false, as shown in the following example. The other workaround is for you to call DirectoryEntry.RefreshCache(), which will reload the cache.

Caution 

When you set the cache to false, you no longer work in the client's memory. Changes are immediately propagated to the server.

Code Example: Directory Cache
Start example

using System;
using System.DirectoryServices;

namespace Chapter12
{


          public class DirectoryBinding
          {
                  public DirectoryBinding()
                  {
                         DirectoryEntry MyDirectoryObject = new DirectoryEntry();

                         MyDirectoryObject.Path = "LDAP://HMSRevenge/rootDSE";
                         MyDirectoryObject.Username = @"redmond\gregmcb";
                         MyDirectoryObject.Password = @"MyPassword";
                         MyDirectoryObject.UsePropertyCache = false;
                         DirectoryEntries MyChildObjects =
                            MyDirectoryObject.Children;

                         PropertyCollection MyAttributes =
                           MyDirectoryObject.Properties;
                         foreach(string MyAttributeName in
                               MyAttributes.PropertyNames)
                         {
                                PropertyValueCollection MyAttributeValues =
                                    MyAttributes[MyAttributeName];
                                foreach(string MyValue in MyAttributeValues)
                                {
                                       Console.WriteLine(MyAttributeName +
                                             " = " + MyValue);
                                }
                         }
                  }
          }
}
End example

Team LiB
Previous Section Next Section