HOW TO:使 Web 網頁與 Outlook 資料夾產生關聯
這個範例會檢查 Microsoft Office Outlook 中名為 HtmlView 的資料夾是否存在。 如果此資料夾不存在,程式碼就會建立此資料夾並指派 Web 網頁給它。 如果此資料夾存在,則程式碼就會顯示資料夾內容。
**適用於:**本主題中的資訊適用於 Outlook 2007 和 Outlook 2010 的應用程式層級專案。如需詳細資訊,請參閱依 Office 應用程式和專案類型提供的功能。
範例
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();
}