2017-02-25 36 views
0

Outlook 2013にアドインを作成中です。MailItemにカスタムフィールドを追加し、AdvancedSearchを使用してアイテムを検索しました。最後に欠けている部分が結果を示しています。Outlook検索で検索結果を表示する方法

検索結果にカスタム検索の結果を表示するにはどうすればよいですか?

private void Application_AdvancedSearchComplete(Outlook.Search SearchObject) 
    { 
     string dx = SearchObject.Tag; 
     int x = SearchObject.Results.Count; 
     //What next? 
    } 

    private void button1_Click(object sender, RibbonControlEventArgs e) 
    { 
     Object selObject = Globals.ThisAddIn.Application.ActiveExplorer().Selection[1]; 
     Outlook.MailItem mail = selObject as Outlook.MailItem; 
     if (mail != null) 
     { 
      Outlook.UserProperties mailUserProperties = null; 
      Outlook.UserProperty mailUserProperty = null; 
      mailUserProperties = mail.UserProperties; 
      foreach (var i in mailUserProperties) 
      { 
       var xx = i; 
      } 
      mailUserProperty = mailUserProperties.Add("TestUserProperty", Outlook.OlUserPropertyType.olText, true); 
      mailUserProperty.Value = "Eugene Astafiev"; 
      mail.Save(); 
     } 

     string str = "http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/TestUserProperty LIKE '%ugene%'"; 
     Outlook.MAPIFolder inbox = Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); 
     Globals.ThisAddIn.Application.AdvancedSearch("Inbox", str, false, "TestUserProperty"); 
    } 

答えて

0

Application.AdvancedSearchの結果を表示することはできません。 UIで検索結果を表示するには、Explorer.Searchを使用する必要があります。これは、UIで検索を実行しているユーザーを効果的に自動化するだけです。ただし、コードで結果を戻すことはできません。オプションの概要については、こちらを参照してください。 https://msdn.microsoft.com/en-us/library/ff869846.aspx

0

結果を検索フォルダに保存してから、ユーザーに表示することができます。 SearchクラスのSaveメソッドは、検索結果を検索フォルダに保存します。 Saveメソッドは、同じ名前の検索フォルダが既に存在する場合はエラーを表示します。

 Outlook.Results 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 
      { 
       strBuilder = new System.Text.StringBuilder(); 
       strBuilder.AppendLine("Number of items found: " + 
          advancedSearchResults.Count.ToString());        
       for (int i = 1; i < = advancedSearchResults.Count; i++) 
       {         
        resultItem = advancedSearchResults[i] 
             as Outlook.MailItem; 
        if (resultItem != null) 
        { 
         strBuilder.Append("#" + i.ToString()); 
         strBuilder.Append(" Subject: " + resultItem.Subject); 
         strBuilder.Append(" \t To: " + resultItem.To); 
         strBuilder.AppendLine(" \t Importance: " + 
              resultItem.Importance.ToString()); 
         Marshal.ReleaseComObject(resultItem); 
        } 
       } 
       if (strBuilder.Length > 0) 
        System.Diagnostics.Debug.WriteLine(strBuilder.ToString()); 
       else 
        System.Diagnostics.Debug.WriteLine(
              "There are no Mail items found."); 
      } 
     } 
     else 
     { 
      System.Diagnostics.Debug.WriteLine("There are no items found."); 
     } 

Advanced search in Outlook programmatically: C#, VB.NETという記事が参考になる場合があります。

関連する問題