HOWTO: Create Address Book View Using ADSI

ID: Q229883


The information in this article applies to:
  • Microsoft Active Directory Service Interfaces, versions 2.0, 2.5


SUMMARY

Address Book View is a mechanism that provides users a way to see recipients grouped by a common attribute. It also allows administrators to control which entries users can see in the global address list.

Using Microsoft Active Directory Service Interfaces (ADSI) through the Lightweight Directory Access Protocol (LDAP), you can create Microsoft Exchange Server Address Book Views. This article shows you how by using either C/C++ or Visual Basic. To see the results of the code sample, check the Exchange Administrator Address Book Views container.


MORE INFORMATION

An Address Book View can be created to group recipients by multiple attributes, where these can be any of the Exchange Server standard or custom attributes.

For simplicity purposes, the following example creates an Address Book View that groups items by Department (single grouping), and with Windows NT accounts with inherited permissions.

This is illustrated by using IDirectoryObject via C/C++:


#include <activeds.h>
//Link with activeds.lib and adsiid.lib<BR/>

   HRESULT            hr;
   IDirectoryObject   *pDirObject=NULL;
   IDispatch          *pDisp=NULL;

   ADSVALUE	classValue;
   ADSVALUE	adminDName;
   ADSVALUE	groupBy;
   ADSVALUE	contValue;
   ADSVALUE	viewFlags;

   // Initialization
   CoInitialize(NULL);
 
   // Prepare attributes to be set
   ADS_ATTR_INFO  attrInfo[] = 
   {  
     {L"objectClass", ADS_ATTR_UPDATE, ADSTYPE_CASE_IGNORE_STRING, &classValue, 1},
     {L"Admin-Display-Name", ADS_ATTR_UPDATE, ADSTYPE_CASE_IGNORE_STRING, &adminDName, 1},
     {L"Group-By-Attr-1", ADS_ATTR_UPDATE, ADSTYPE_CASE_IGNORE_STRING, &groupBy, 1},
     {L"Container-Info", ADS_ATTR_UPDATE, ADSTYPE_CASE_IGNORE_STRING, &contValue, 1},
     {L"View-Flags", ADS_ATTR_UPDATE, ADSTYPE_CASE_IGNORE_STRING, &viewFlags, 1}
   };

   DWORD dwAttrs = sizeof(attrInfo)/sizeof(ADS_ATTR_INFO); 
 
   classValue.dwType = ADSTYPE_CASE_IGNORE_STRING;
   classValue.CaseIgnoreString = L"View-Container";

   adminDName.dwType = ADSTYPE_CASE_IGNORE_STRING;
   adminDName.CaseIgnoreString = L"Department";

   groupBy.dwType=ADSTYPE_CASE_IGNORE_STRING;
   groupBy.CaseIgnoreString = L"department";
 
   contValue.dwType=ADSTYPE_CASE_IGNORE_STRING;
   contValue.CaseIgnoreString = L"-2147475456";

   viewFlags.dwType=ADSTYPE_CASE_IGNORE_STRING;
   viewFlags.CaseIgnoreString = L"1";
 
   // Bind to base container object
   hr = ADsGetObject(L"LDAP://<server>/ou=_ABViews_,o=<org>", IID_IDirectoryObject, (void**) &pDirObject );
 
   if ( SUCCEEDED(hr) )
   {
      // Create the address book view object
      hr = pDirObject->CreateDSObject(L"rdn=Department_V", attrInfo, dwAttrs, &pDisp);
      pDisp->Release();
   }
	
   // Clean-up
   pDirObject->Release();	
   CoUninitialize();
 
Since IDirectoryObject interface is not available to automation-base languages, the task is illustrated with Visual Basic by using IADs interface. To do this, make a reference to Active DS Type Library in your Microsoft Visual Basic project:

Dim c_ExchABView As IADsContainer
Dim o_View As IADs

Set c_ExchABView = GetObject("LDAP://<server>/ou=_ABViews_,o=<org>")
Set o_View = c_ExchABView.Create("View-Container", "rdn=Department_V")

o_View.Put "Admin-Display-Name", "Department"  'Admin-Display-Name
o_View.Put "Group-By-Attr-1", "department"     'Group Criteria (Department)
o_View.Put "Container-Info", "-2147475456"     'Used by Exchange Server
o_View.Put "View-Flags", "1"                   'View Flags

o_View.SetInfo 

Additional query words: kbXchge kbXchge550 kbMsg kbADSI kbGrpMsg kbVC

Keywords : kbADSI kbXchge kbXchge550 kbMsg kbVC kbGrpMsg
Version : winnt:2.0,2.5
Platform : winnt
Issue type : kbhowto


Last Reviewed: September 30, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.