Microsoft KB Archive/263175

= OL2000: How to Programmatically Set a Public Folder Offline =

Article ID: 263175

Article Last Modified on 8/29/2007

-

APPLIES TO


 * Microsoft Outlook 2000 Standard Edition

-



This article was previously published under Q263175



SUMMARY
This article describes how to use the Microsoft Outlook object model and the Collaboration Data Objects (CDO) object model to programmatically add a public folder to your Favorites folder, and then to configure the public folder to use offline.



MORE INFORMATION
The Outlook object model does not provide a direct method to set the offline availability of a folder, however, this property is accessible through the CDO object model. In order to programmatically set a public folder for offline synchronization, first copy a public folder to your Favorites folder, and then change the folder's offline property.

This sample code uses the Outlook object model to add a public folder to your Favorites folder, and then to use CDO to make the folder available offline. This sample code is written in Microsoft Outlook Visual Basic for Applications and provides a starting point for the development of a complete solution.

For additional information about the AddToPFFavorites method, click the article number below to view the article in the Microsoft Knowledge Base:

239005 OL2000: AddToPFFavorites Method Can Add Folder to Favorites

Programming Considerations

 * You need to set a reference to the Microsoft CDO 1.21 Library. CDO is an optional component of the Outlook 2000 installation procedure.
 * The Outlook profile that is used with this code must be configured for offline synchronization.
 * The sample code starts offline synchronization to allow the Offline Flags field for the folder to update correctly. The code does not work correctly if you do not start offline synchronization.
 * Before you run the sample code, you must click the public folder that you want to use offline.

Sample Code
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:

https://partner.microsoft.com/global/30000104

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

Sub SetOffline

Const PR_OFFLINE_FLAGS = &H663D0003 ' 5656 is the identification number for the &quot;Synchronize All Folders&quot; ' button Const All_Folders = 5656

Dim curFolder As Outlook.MAPIFolder Dim oFavFldr As Outlook.MAPIFolder Dim oFavorites As Outlook.MAPIFolder Dim oCDOSession As MAPI.Session Dim oFolder As MAPI.Folder Dim SyncAll As CommandBarControl Dim i As Integer

Set curFolder = ActiveExplorer.CurrentFolder curFolder.AddToPFFavorites

'Reference and click the &quot;All Folders&quot; synchronization button Set SyncAll = ActiveExplorer.CommandBars.FindControl(, All_Folders) SyncAll.Execute

'Short pause For i = 1 To 10000 DoEvents Next

' Create a CDO session Set oCDOSession = New MAPI.Session oCDOSession.Logon ShowDialog:=False, NewSession:=False

' Use the Outlook object model to find the public folder in the ' Favorites folder that matches the name of the current public folder Set oFavorites = Session.Folders(&quot;Public Folders&quot;).Folders(&quot;Favorites&quot;) Set oFavFldr = oFavorites.Folders(curFolder.Name)

' Reference the folder in CDO by using the EntryID method ' that is obtained through the Outlook object model Set oFolder = oCDOSession.GetFolder(oFavFldr.EntryID, oFavFldr.StoreID) oFolder.Update True, False

' Set the folder availability: ' 0 = Only when online ' 1 = When offline or online oFolder.Fields(PR_OFFLINE_FLAGS).Value = 1 oFolder.Update

oCDOSession.Logoff

'Clean up  Set SyncAll = Nothing Set curFolder = Nothing Set oFavorites = Nothing Set oFavFldr = Nothing Set oFolder = Nothing Set oCDOSession = Nothing

End Sub

