Retrieving Folder Tree URLs
Retrieving Folder Tree URLs
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
Folder tree URLs are required for various store management operations. The following code will locate a folder tree by name on an Exchange 2000 server. It will return the full URL, which you can use when creating a store.
Visual Basic
'////////////////////////////////////////////////////////////////////////////////// '// Name: GetFolderTreeURL '// Purpose: To get the Folder Tree Hierarchies URL '// Input: strComputerName = contains the name of the Exchange 2000 Server '// strFHName = containes the name of the Folder Tree Hierarchy to be found '// Output: Nothing '// '// Notes: The subroutine is useful for checking to see if this folder tree url '// is already in use. Also it is useful when creating a new '// public or mailbox store (since they require a folder tree URL). '// '////////////////////////////////////////////////////////////////////////////////// Public Sub GetFolderTreeURL(ByVal strComputerName As String, _ ByRef strFHName As String) On Error Resume Next Dim RootDSE As IADs Dim conf As IADs Dim conn As New ADODB.Connection Dim comm As New ADODB.Command Dim rs As ADODB.Recordset 'Get the default IExchangeServer interface Dim iServer As New CDOEXM.ExchangeServer Dim strPath As String Dim strDSAdminName As String Dim strDSAdminPass As String Dim strDNFolder As String strFHName = "" ' Bind to the Exchange Server iServer.DataSource.Open strComputerName Set RootDSE = GetObject("LDAP://" + iServer.DirectoryServer + "/RootDSE") strPath = "LDAP://" & iServer.DirectoryServer & "/" & RootDSE.Get("configurationNamingContext") ' Set the Provider for the connection object conn.Provider = "ADsDSOObject" 'You will need to provide login credentials if you are not logged in 'with an administrator security context. ' Open connection conn.Open ' Set command to connection object Set comm.ActiveConnection = conn comm.CommandText = "<" & strPath & ">" & ";(objectClass=msExchPFTree);ADsPath,distinguishedName,Name;subtree" ' Execute command Set rs = comm.Execute ' Get the Default FolderTreeHierarcy Do While Not (rs.EOF) 'You can print access folder tree information here 'Debug.Print rs.Fields("ADsPath").Value 'Debug.Print rs.Fields("distinguishedName") 'Debug.Print rs.Fields("Name") strDNFolder = rs.Fields("distinguishedName") 'cut the folder name to get the Folder Hierarchies strFHName = Mid(strDNFolder, InStr(2, strDNFolder, "CN=")) If strFHName <> "" Then Exit Do Else rs.MoveNext End If Loop ' test if the URL to the FolderTreeHierarcy is empty If strFHName = "" Then Debug.Print "No Folder Hierarchy Name Found." End If 'Cleanup Set RootDSE = Nothing Set conf = Nothing Set conn = Nothing Set comm = Nothing Set rs = Nothing Set iServer = Nothing End Sub
Send us your feedback about the Microsoft Exchange Server 2003 SDK.
Build: June 2007 (2007.618.1)
© 2003-2006 Microsoft Corporation. All rights reserved. Terms of use.