代表一組可能是異質性的 Microsoft Outlook 項目,其中每個成員只追蹤套用至一般 Outlook 項目的一小組共通屬性。
註解
SimpleItems 集合是用來代表 Conversation 節點物件的子物件。 此集合只有少數成員,目的是提供對這些項目的輕鬆存取,與擁有更多成員的 項目 和 結果 集合相反。
此集合中項目的順序與交談中項目的順序相同。 此集合是以遞減順序依每個項目的 CreationTime 屬性值排定順序。
範例
The following managed code is written in C#. To run a .NET Framework managed code sample that needs to call into a Component Object Model (COM), you must use an interop assembly that defines and maps managed interfaces to the COM objects in the object model type library. For Outlook, you can use Visual Studio and the Outlook Primary Interop Assembly (PIA). Before you run managed code samples for Outlook 2013, ensure that you have installed the Outlook 2013 PIA and have added a reference to the Microsoft Outlook 15.0 Object Library component in Visual Studio. 您應該在 Outlook 增益集類別中使用 ThisAddIn 以下代碼 (使用適用於 Visual Studio) 的 Office 開發人員工具。 程式碼中的 Application 物件必須是由 提供信任ThisAddIn.Globals的 Outlook Application 物件。 如需使用 Outlook PIA 開發受管理 Outlook 解決方案的詳細資訊,請參閱 MSDN 上的 歡迎使用 Outlook 主要互通組件參考 。
下列程式碼範例假設 [檔案總管] 視窗中選取的項目是郵件項目。 此範例會取得與所選郵件項目相關聯的交談,並列舉該交談中的每個項目,並顯示項目的主旨。
DemoConversation此方法會呼叫所選郵件項目的 GetConversation 方法,以取得關聯的 Conversation 物件。
DemoConversation然後呼叫 Conversation 物件的 GetTable 和 GetRootItems 方法,以分別取得 Table 物件和 SimpleItems 集合。
DemoConversation 呼叫 Recurrent 方法 EnumerateConversation ,列舉並顯示該交談中每個項目的主旨。
void DemoConversation()
{
object selectedItem =
Application.ActiveExplorer().Selection[1];
// This example uses only
// MailItem. Other item types such as
// MeetingItem and PostItem can participate
// in the conversation.
if (selectedItem is Outlook.MailItem)
{
// Cast selectedItem to MailItem.
Outlook.MailItem mailItem =
selectedItem as Outlook.MailItem;
// Determine the store of the mail item.
Outlook.Folder folder = mailItem.Parent
as Outlook.Folder;
Outlook.Store store = folder.Store;
if (store.IsConversationEnabled == true)
{
// Obtain a Conversation object.
Outlook.Conversation conv =
mailItem.GetConversation();
// Check for null Conversation.
if (conv != null)
{
// Obtain Table that contains rows
// for each item in the conversation.
Outlook.Table table = conv.GetTable();
Debug.WriteLine("Conversation Items Count: " +
table.GetRowCount().ToString());
Debug.WriteLine("Conversation Items from Table:");
while (!table.EndOfTable)
{
Outlook.Row nextRow = table.GetNextRow();
Debug.WriteLine(nextRow["Subject"]
+ " Modified: "
+ nextRow["LastModificationTime"]);
}
Debug.WriteLine("Conversation Items from Root:");
// Obtain root items and enumerate the conversation.
Outlook.SimpleItems simpleItems
= conv.GetRootItems();
foreach (object item in simpleItems)
{
// In this example, enumerate only MailItem type.
// Other types such as PostItem or MeetingItem
// can appear in the conversation.
if (item is Outlook.MailItem)
{
Outlook.MailItem mail = item
as Outlook.MailItem;
Outlook.Folder inFolder =
mail.Parent as Outlook.Folder;
string msg = mail.Subject
+ " in folder " + inFolder.Name;
Debug.WriteLine(msg);
}
// Call EnumerateConversation
// to access child nodes of root items.
EnumerateConversation(item, conv);
}
}
}
}
}
void EnumerateConversation(object item,
Outlook.Conversation conversation)
{
Outlook.SimpleItems items =
conversation.GetChildren(item);
if (items.Count > 0)
{
foreach (object myItem in items)
{
// In this example, enumerate only MailItem type.
// Other types such as PostItem or MeetingItem
// can appear in the conversation.
if (myItem is Outlook.MailItem)
{
Outlook.MailItem mailItem =
myItem as Outlook.MailItem;
Outlook.Folder inFolder =
mailItem.Parent as Outlook.Folder;
string msg = mailItem.Subject
+ " in folder " + inFolder.Name;
Debug.WriteLine(msg);
}
// Continue recursion.
EnumerateConversation(myItem, conversation);
}
}
}
方法
| 名稱 |
|---|
| 項目 |
屬性
| 名稱 |
|---|
| Application |
| Class |
| Count |
| Parent |
| Session |
另請參閱
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。