如何以编程方式更新Outlook Search文件夹结果以进行新搜索而不更改文件夹名称

时间:2019-03-26 12:07:13

标签: outlook office-interop addin-express

我使用add-in express为Outlook插件创建了Outlook搜索文件夹,如下所示。它基于此article。 有类似的方法来更新新结果的搜索文件夹名称吗?

private void adxOutlookEvents_AdvancedSearchComplete(object sender, object hostObj) { 
        Outlook.Search advancedSearch = null; 
        Outlook.Results advancedSearchResults = null; 
        Outlook.MailItem resultItem = null; 
        System.Text.StringBuilder strBuilder = null; 
        try { 
            advancedSearch = hostObj as Outlook.Search; 
            if (advancedSearch.Tag == advancedSearchTag) { 
                System.Diagnostics.Debug.WriteLine("!!! adxOutlookEvents_AdvancedSearchComplete"); 
                advancedSearchResults = advancedSearch.Results; 
                if (advancedSearchResults.Count > 0) { 
                    if (HostMajorVersion > 10) { 
                        object folder = advancedSearch.GetType().InvokeMember("Save", 
                                            System.Reflection.BindingFlags.Instance | 
                                            System.Reflection.BindingFlags.InvokeMethod | 
                                            System.Reflection.BindingFlags.Public, 
                                            null, advancedSearch, 
                                            new object[] { advancedSearchTag }); 

                    }  
                } else { 
                    System.Diagnostics.Debug.WriteLine("!!!" + "There are no items found."); 
                } 
            } 
        } catch (Exception ex) { 
            MessageBox.Show(ex.Message, "An exception is occured"); 
        } finally { 
            if (resultItem != null) Marshal.ReleaseComObject(resultItem); 
            if (advancedSearchResults != null) 
                Marshal.ReleaseComObject(advancedSearchResults); 
        } 
    } 

1 个答案:

答案 0 :(得分:1)

Application.AdvancedSearch返回Search对象。您可以通过传递名称(字符串)来调用Search.Save-它会返回MAPIFolder对象。您可以随时修改MAPIFolder.Name属性。