How to: Programmatically Associate a Web Page with an Outlook Folder


This example checks for a folder named HtmlView in Microsoft Office Outlook. If the folder does not exist, the code creates the folder and assigns a Web page to it. If the folder exists, the code displays the folder contents.

Applies to: The information in this topic applies to VSTO add-in projects for Outlook. For more information, see Features Available by Office Application and Project Type.

        private void CreateHtmlFolder()
            Outlook.MAPIFolder newView = null;
            string viewName = "HtmlView";
            Outlook.MAPIFolder inBox = (Outlook.MAPIFolder)
            Outlook.Folders searchFolders = (Outlook.Folders)inBox.Folders;
            bool foundView = false;
            foreach (Outlook.MAPIFolder searchFolder in searchFolders)
                if (searchFolder.Name == viewName)
                    newView = inBox.Folders[viewName];
                    foundView = true;
            if (!foundView)
                newView = (Outlook.MAPIFolder)inBox.Folders.
                    Add("HtmlView", Outlook.OlDefaultFolders.olFolderInbox);
                newView.WebViewURL = "";
                newView.WebViewOn = true;

Working with Folders
How to: Programmatically Retrieve a Folder by Name
How to: Programmatically Create Custom Folder Items