我需要从outlook addin(c#+ vsto)中调用outlook的会话清理。 我在办公室功能区栏上有我的按钮,点击它后,需要在当前选择的邮件项目上调用outlook的对话清理。 这是可能的,如何去做?
答案 0 :(得分:0)
Outlook项目提供GetConversation方法,该方法获取表示此项目所属对话的Conversation
对象。
GetConversation
将返回Null
(在Visual Basic中为Nothing)。在以下情况下,项目不存在对话:
•项目尚未保存。可以通过编程,用户操作或自动保存来保存项目。
•对于可以发送的项目(例如,邮件项目,约会项目或联系项目),该项目尚未发送。
•已通过Windows注册表禁用了对话。
•商店不支持“对话”视图(例如,Outlook在Microsoft Exchange Server 2010之前的Microsoft Exchange版本的经典在线模式下运行)。使用Store对象的IsConversationEnabled属性来确定商店是否支持“对话”视图。
以下代码示例假定资源管理器窗口中的所选项目是邮件项目。代码示例获取与所选邮件项关联的对话,并枚举该对话中的每个项目,显示该项目的主题。 DemoConversation
方法调用所选邮件项的GetConversation
方法以获取关联的Conversation对象。 DemoConversation
然后调用Conversation对象的GetTable
和GetRootItems
方法分别获取Table对象和SimpleItems集合。
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, only enumerate 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, only enumerate 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);
}
}
}