Share via


Creating a Public Store

Creating a Public Store

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.

The code in the following example creates a public store in a storage group. Note that when you are creating a public store, you must specify a folder tree. The folder tree specifies where the data in the store is to appear in the Exchange store. For more information, see Managing Exchange Server.

Visual Basic

'//////////////////////////////////////////////////////////////////////////////////
'// Name:       CreateNewPublicStore
'// Purpose:    To create a new PublicStoreDB with a given name
'// Input:      strPSName = contains the name of the new PublicStoreDB to be created
'//             strFolderName = contains the name of the related Public Folder
'//             strComputerName = contains the name of the Exchange 2000 server
'//             blnMount (Optional) = True if the new PublicStoreDB will be mounted after creation
'//                                 = False if the new PublicStoreDB will not be mounted
'//             strSGName (Optional) = contains the name of the storage group to create the New PublicStoreDB in;
'//                                    if it's empty then the new PublicStoreDB will be created in the default Storage Group
'//             strMDBUrl (Optional ByRef) = contains the URL to the new PublicStoreDB created;
'//
'//////////////////////////////////////////////////////////////////////////////////

Sub CreateNewPublicStore(ByVal strPSName As String, _
                              ByVal strFolderName As String, _
                              ByVal strComputerName As String, _
                              Optional ByVal blnMount As Boolean, _
                              Optional ByVal strSGName As String, _
                              Optional ByRef strPSUrl As String)

    Dim iServer         As New CDOEXM.ExchangeServer
    Dim iPbStoreDB      As New CDOEXM.PublicStoreDB
    Dim arrStGroup()    As Variant
    Dim i               As Integer
    Dim strTemp         As String
    Dim strFolderURL    As String
    Dim strFHName       As String

    ' Bind to the Exchange Server
    iServer.DataSource.Open strComputerName

    ' Get the FolderTreeHierarcy to build the URL to the Public Folder
    GetFolderTreeURL strComputerName, strFHName

    ' Build the URL to the PublicFolderTree
    strFolderURL = "LDAP://" & iServer.DirectoryServer & "/CN=" & strFolderName & "," & strFHName

    ' Set the variant array to the array of StorageGroups from Server object
    arrStGroup = iServer.StorageGroups
    ' Start to build the URL to the PublicStore - first part
    strTemp = "LDAP://" & iServer.DirectoryServer & "/CN=" & strPSName & ","

    ' Set the name of the PublicStoreDB
    iPbStoreDB.Name = strPSName
    ' Set the name of the PublicFolderTree
    iPbStoreDB.FolderTree = strFolderURL

    ' Verify if the StorageGroup strSGName exist in the StorageGroups array
    If strSGName = "" Then
        ' Finish to build the URL to the PublicStoreDB -  add last part
        strPSUrl = strTemp & iServer.StorageGroups(0)
    Else
        For i = 0 To UBound(arrStGroup)
            If InStr(1, arrStGroup(i), strSGName) <> 0 Then
                ' Finish to build the URL to the PublicStoreDB -  add last part
                strPSUrl = strTemp & arrStGroup(i)
            End If
        Next
    End If

    ' Save the PublicStoreDB
    iPbStoreDB.DataSource.SaveTo strPSUrl

    ' Mount the PublicStoreDB if the blnMount is True
    If blnMount = True Then
        iPbStoreDB.Mount
    End If

    ' Cleanup
    Set iServer = Nothing
    Set iPbStoreDB = Nothing

End Sub

The preceding sample calls GetFolderTreeURL(). This retrieves the folder tree full URL that is used to specify the location of the store data in the Exchange store. See Retrieving Folder Tree URLs for an explanation of GetFolderTreeURL.

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.