How to: Associate a Web Page with an Outlook Folder
Applies to |
---|
The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office. Project type
Microsoft Office version
For more information, see Features Available by Application and Project Type. |
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.
Example
Private Sub CreateHtmlView()
Dim newView As Outlook.MAPIFolder = Nothing
Dim viewName As String = "HtmlView"
Dim inBox As Outlook.MAPIFolder = Me.Application.ActiveExplorer(). _
Session.GetDefaultFolder(Outlook.OlDefaultFolders _
.olFolderInbox)
Dim searchFolders As Outlook.Folders = inBox.Folders()
Dim foundView As Boolean = False
For Each searchFolder As Outlook.MAPIFolder In searchFolders
If searchFolder.Name = viewName Then
newView = inBox.Folders(viewName)
foundView = True
End If
Next
If foundView = False Then
newView = inBox.Folders.Add(viewName, _
Outlook.OlDefaultFolders.olFolderInbox)
newView.WebViewURL = "https://www.microsoft.com"
newView.WebViewOn = True
End If
Application.ActiveExplorer.SelectFolder(newView)
Application.ActiveExplorer.CurrentFolder.Display()
End Sub
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 = "https://www.microsoft.com";
newView.WebViewOn = true;
}
Application.ActiveExplorer().SelectFolder(newView);
Application.ActiveExplorer().CurrentFolder.Display();
}
See Also
Tasks
How to: Retrieve a Folder by Name
How to: Create Custom Folder Items