Recipe9.7.Creating and Deleting Public Folders


Recipe 9.7. Creating and Deleting Public Folders

Problem

You want to create or remove public folders from a public folder tree.

Solution

Using a graphical user interface

To create a folder, do the following:

  1. Launch the Exchange System Manager (Exchange System Manager.msc).

  2. In the left pane, expand the appropriate Administrative Groups container.

  3. Expand the Folders node, then expand the container for the TLH where you want the new folder created.

  4. Right-click the TLH container and select New Public Folder.

  5. Optionally, switch to the Replication tab and use the Add and Remove buttons to control which servers have replicas of the newly created folders.

  6. Click OK.

To delete a folder, do the following:

  1. Launch the Exchange System Manager (Exchange System Manager.msc).

  2. In the left pane, expand the appropriate Administrative Groups container.

  3. Expand the Folders node, then expand the container for the TLH where you want the new folder created.

  4. Find the folder you want to remove, right-click it, and select Delete.

Using VBScript
' This code creates a folder with the specified name at the top level ' of the MAPI TLH. ' ------ SCRIPT CONFIGURATION ------  strFolderName = "<folderName>"     ' e.g., "Bad Jokes"   ' ------ END CONFIGURATION --------- ' Get the default domain name. This is not necessarily ' the same as the AD domain name, which is why we have to ' get it from the recipient policy object     Set objDefaultPolicy = GetObject( _          "LDAP://<dcName>/cn=default policy,cn=recipient policies," &_                   "cn=<orgName>,cn=microsoft exchange,cn=services," &_                   "cn=configuration,dc=<domain>,dc=<TLD>")      ' get all of the proxy addresses in the default recipient       ' policy. Find the default SMTP policy and that'll tell us      ' what the default Exchange domain is     strProxies = objDefaultPolicy.Get("gatewayProxy")     For Each proxyAddr In strProxies         If (Left(proxyAddr, 5) = "SMTP:") Then         strStorageName = Right(proxyAddr, Len(proxyAddr)-InStr(proxyAddr, "@"))         End if     Next          ' Build the path to the storage object.     strStorageName = "file://./backofficestorage/" + strStorageName + "/"         ' Create the folder.object     strFolderPath = strStorageName + "public folders/" + strFolderName     Set theFolder = CreateObject("cdo.folder")     ' Set the folder properties.     With theFolder         .Description = "Root folder for " + strFolderName         .ContentClass = "urn:content-classes:folder"         .fields("http://schemas.microsoft.com/exchange" &_             "/outlook/outlookfolderclass") = _             "IPF.Folder"         .Fields.Update         .DataSource.SaveTo strFolderPath    End With WScript.Echo "Done creating folders."

Discussion

If your account has appropriate permissions, you can also create and delete public folders directly from within Outlook; you do this using the same process you'd use for creating or deleting any other kind of folder with a few exceptions. First, you can only create and remove public folders while you're online with the server. Even though cached Exchange mode has an option to automatically cache posted items in public folders on your favorites list, you can't add or remove folders. Second, when you create a new folder, Outlook asks you to specify what kind of items (contacts, calendar items, notes, or messages) will go in the folder; ESM doesn't care, so it doesn't ask.

Using VBScript

The code creates a new folder by creating a CDO folder object and assigning it a path in the MAPI public folder tree. To do this, we have to find the correct default domain name for Exchange. This name may or may not be the same as the Active Directory domain name; the simplest way to check is to look at the primary SMTP proxy address on the default recipient policy, so that's what the script does. Once the script has the correct name, it can specify the location of the folder and create it using CDO.

This will only work for accounts that have permission to create top-level public folders. There's no good way to use the same interfaces to delete a public folder, since the data in the folder is only permanently deleted when you delete the last replica of that folder. If you try to use this method to create a folder that already exists, you'll get error 0x80040e98, which isn't well-documented on MSDN (or anywhere else). The associated error string will say that the requested object cannot be shared; what it should say is that the object exists already.

See Also

Recipe 9.3 for getting and setting permissions, Recipe 9.8 for mail-enabling or mail-disabling a folder, Recipe 9.11 for controlling who can create top-level public folders, and MSDN: CDO



Exchange Server Cookbook
Exchange Server Cookbook: For Exchange Server 2003 and Exchange 2000 Server
ISBN: 0596007175
EAN: 2147483647
Year: 2006
Pages: 235

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net