FolderNames Property and Dynamic Folders

Add-in Express™ Support Service
That's what is more important than anything else

FolderNames Property and Dynamic Folders
 
Minhaj Khan




Posts: 15
Joined: 2006-08-17

Hi

I had a folder created at startup with webviewpane layout plus some registry related code deployed. During execution, numerous folders are created on the fly. How can FolderNames property be set dynamically to cater for newly created folders?

Please note that these folders are created as sub-folders beneath root folders, and also want to retain webviewpane layout for these folders.

I had observed that Key.SetValue() does not write folder names, additionally retrieval Key.GetValue() throws invalid cast exception.

Thanks in advance.

Minhaj
Posted 13 Oct, 2006 08:10:51 Top
Fedor Shihantsov


Guest


Minhaj,

Sorry for the delay. Please note, that if we don't answer your message you can resend the message anew.

First off, you can add Folders Events Class using "Add | New Item | Add-in Express Items | Outlook Folders Events Class" dialog.

Create an instance of OutlookFoldersEventsClass in the AddinStartupComplete event. Below I create such an instance and connect it to the root folder:


OutlookFoldersEventsClass1 folderEvents = null;
private void AddinModule_AddinStartupComplete(object sender, EventArgs e)
{
    folderEvents = new OutlookFoldersEventsClass1(this);
    Outlook.MAPIFolder inboxFolder = OutlookApp.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
    Outlook.MAPIFolder rootFolder = inboxFolder.Parent as Outlook.MAPIFolder;
    folderEvents.ConnectTo(rootFolder, true);
    Marshal.ReleaseComObject(inboxFolder);
    Marshal.ReleaseComObject(rootFolder);
}

private void AddinModule_AddinBeginShutdown(object sender, EventArgs e)
{
    folderEvents.Dispose();
}


This sample allows you to process events of the Folders collection of the root folder. To process other folders, you should create an instance of OutlookFoldersEventsClass for each folder and connect the instance to the folder.

Set the ADXOlFormsCollectionItem.FolderNames property in the ProcessFolderAdd method, say the way I do it below:


public override void ProcessFolderAdd(object folder)
{
    AddinExpress.OL.ADXOlFormsManager formsManager = (this.Module as NewFolderEvent.AddinModule).adxOlFormsManager1;
    string folderName = "Personal Folders\" + (folder as Outlook.MAPIFolder).Name;
    formsManager.LockUpdates(); 
    formsManager.Items[0].FolderNames.Add(folderName);
    formsManager.UnlockUpdates();
}


To get the full path of a folder in Outlook 2003 you can use the FolderPath property of the MAPIFolder object.
Posted 27 Oct, 2006 12:51:48 Top