简体   繁体   English

从Outlook加载项调用对话清理

[英]Calling conversation cleanup from outlook add-in

I need to call outlook's conversation cleanup from my outlook addin (c# + vsto). 我需要从我的Outlook插件(C#+ vsto)中调用Outlook的对话清理。 I have my button on the office ribbon bar and on clicking it it needs to invoke outlook's conversation cleanup on the currently selected mail item. 我在办公室功能区栏上有我的按钮,单击它需要在当前选定的邮件项目上调用Outlook的对话清除。 Is this possible and how to go about it? 这可能吗,怎么办?

Outlook items provide the GetConversation method which obtains a Conversation object that represents the conversation to which this item belongs. Outlook项目提供GetConversation方法,该方法获得一个Conversation对象,该对象表示该项目所属的会话。

GetConversation returns Null (Nothing in Visual Basic) if no conversation exists for the item. 如果该项目不存在对话,则GetConversation返回Null (在Visual Basic中为Nothing)。 No conversation exists for an item in the following scenarios: 在以下情况下,项目的对话不存在:

•The item has not been saved. •该项目尚未保存。 An item can be saved programmatically, by user action, or by auto-save. 可以以编程方式,通过用户操作或通过自动保存来保存项目。

•For an item that can be sent (for example, a mail item, appointment item, or contact item), the item has not been sent. •对于可以发送的项目(例如邮件项目,约会项目或联系人项目),尚未发送该项目。

•Conversations have been disabled through the Windows registry. •对话已通过Windows注册表禁用。

•The store does not support Conversation view (for example, Outlook is running in classic online mode against a version of Microsoft Exchange earlier than Microsoft Exchange Server 2010). •该存储区不支持“对话”视图(例如,Outlook在经典联机模式下针对Microsoft Exchange Server 2010之前的版本运行)。 Use the IsConversationEnabled property of the Store object to determine whether the store supports Conversation view. 使用Store对象的IsConversationEnabled属性来确定商店是否支持“对话”视图。

The following code example assumes that the selected item in the explorer window is a mail item. 下面的代码示例假定资源管理器窗口中的选定项目是邮件项目。 The code example gets the conversation that the selected mail item is associated with, and enumerates each item in that conversation, displaying the subject of the item. 该代码示例获取与所选邮件项目相关联的对话,并枚举该对话中的每个项目,显示该项目的主题。 The DemoConversation method calls the GetConversation method of the selected mail item to get the associated Conversation object. DemoConversation方法调用所选邮件项目的GetConversation方法以获取关联的Conversation对象。 DemoConversation then calls the GetTable and GetRootItems methods of the Conversation object to get a Table object and SimpleItems collection, respectively. DemoConversation然后调用GetTableGetRootItems对话对象的方法来获取表对象和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); 
            } 
         } 
      } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM