Share via


Creating a Public Folder

Creating a Public Folder

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 following example creates a MAPI public folder with a specified name.

Visual Basic

'//////////////////////////////////////////////////////////////////////
' Function: createPublicFolder()
' Purpose:  Creates a mapi public folder with the specified name (from the
'           root of the mapi folder tree).
'
' Input:    szFolderName:       Name of folder
'           szUserName:         Credentials (Username)
'           szUserPwd:          Credentials (PWD)
'
' Output:   createPublicFolder  Contains Error code (if any)
'
' Note:  In order for this example to function correctly, it may be necessary to include
' references to the following libraries: Active DS Type Library, Microsoft CDO for
' Exchange Management Library, Microsoft Cluster Service Automation Classes,
' Microsoft CDO for Windows 2000 Library.
'//////////////////////////////////////////////////////////////////////
Public Function createPublicFolder(ByVal szFolderName As String, _
                                   ByVal szUserName As String, _
                                   ByVal szUserPwd As String) As Integer

    Dim objFolder As Variant
    Dim szConnString As String
    Dim oSysInfo As ActiveDs.ADSystemInfo
    Dim szDomainDNSName As String
    Dim szStorageName As String

    On Error GoTo errhandler

    ' Get the domain name.
    Set oSysInfo = New ActiveDs.ADSystemInfo
    szDomainDNSName = oSysInfo.DomainDNSName

    ' Get the storage name.
    szStorageName = "file://./backofficestorage/" + szDomainDNSName + "/"

    ' Create the folder.
    szConnString = szStorageName + "public folders/" + szFolderName

    Set objFolder = CreateObject("cdo.folder")

    ' Set the folder properties.
    With objFolder
        .Description = "Root folder for " + szFolderName
        .ContentClass = "urn:content-classes:folder"
        .Fields("https://schemas.microsoft.com/exchange/outlook/outlookfolderclass") = "IPF.Folder"
        .Fields.Update
        .DataSource.SaveTo szConnString
    End With

    createPublicFolder = 0

    ' Clean up.
    Set objFolder = Nothing
    Set oSysInfo = Nothing

    Exit Function

    ' Error handling.
errhandler:

    createPublicFolder = 1
    ' Implement error logging here.
    Exit Function

End Function

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.