outlookoffice-interopaddin-express

How to update outlook Search folder result for a new search programmaticaly without changing the folder name


I created Outlook search folder using add-in express for a outlook plugin as below. it is based on this article. is there similar way to update search folder name for a new result ?

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); 
        } 
    } 

Solution

  • Application.AdvancedSearch returns Search object. You can call Search.Save passing the name (string) - it will return MAPIFolder object. You can modify the MAPIFolder.Name property at any time.