Compartilhar via


Associate a web page with an Outlook folder

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

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.

Example

private void CreateHtmlFolder()
{
    Outlook.MAPIFolder newView = null;
    string viewName = "HtmlView";
    Outlook.MAPIFolder inBox = (Outlook.MAPIFolder)
        this.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook
        .OlDefaultFolders.olFolderInbox);
    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 = "http://www.microsoft.com";
        newView.WebViewOn = true;
    }
    Application.ActiveExplorer().SelectFolder(newView);
    Application.ActiveExplorer().CurrentFolder.Display();
}

See also