2009-08-24 11 views
3

Ich versuche, die Eigenschaften eines Microsoft.Office.Interop.Outlook.ContactItem Objekt aufzuzählen (seien wir ci nennen) mit diesem Code:Aufzählen Outlook ContactItem Eigenschaften

 System.Reflection.BindingFlags bf = System.Reflection.BindingFlags.Default; 

     foreach (System.Reflection.PropertyInfo pi in ci.GetType().GetProperties(bf)) 
     { 
      Console.WriteLine("Property Info {0}", pi.Name); 
     } 

Ich habe tatsächlich versucht, mehrere Kombinationen von BindingFlag-Werten, aber keine Eigenschaften werden jemals zurückgegeben.

So wird ContactItem definiert: mit System.Runtime.InteropServices;

namespace Microsoft.Office.Interop.Outlook 
{ 
    [Guid("00063021-0000-0000-C000-000000000046")] 
    [CoClass(typeof(ContactItemClass))] 
    public interface ContactItem : _ContactItem, ItemEvents_10_Event 
    { 
    } 
} 

Dies ist, wie _ContactItem definiert ist (ich habe nur 3 Requisiten für Einfachheit gehalten):

using System; 
using System.Runtime.InteropServices; 

namespace Microsoft.Office.Interop.Outlook 
{ 
    [TypeLibType(4160)] 
    [Guid("00063021-0000-0000-C000-000000000046")] 
    public interface _ContactItem 
    { 
     [DispId(14848)] 
     string Account { get; set; } 
     [DispId(63511)] 
     Actions Actions { get; } 
     [DispId(14913)] 
     DateTime Anniversary { get; set; } 
    } 
} 

Kann mir jemand helfen?

Vielen Dank im Voraus

Bob

Antwort

5

Sie müssen manuell die Schnittstellen nicht definieren. Fügen Sie einfach einen Verweis auf „Microsoft Outlook XX.0 Klassenbibliothek“ zu Ihrem C# -Projekt, und dann Code ähnlich wie diese verwenden:

using System; 
using Outlook = Microsoft.Office.Interop.Outlook; 

namespace OutlookTest 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      Outlook.Application olApplication = new Outlook.Application(); 

      // get nameSpace and logon. 
      Outlook.NameSpace olNameSpace = olApplication.GetNamespace("mapi"); 
      olNameSpace.Logon("Outlook", "", false, true); 

      // get the contact items 
      Outlook.MAPIFolder _olContacts = olNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts); 
      Outlook.Items olItems = _olContacts.Items; 

      foreach (object o in olItems) 
      { 
       if (o is Outlook.ContactItem) 
       { 
        Outlook.ContactItem contact = (Outlook.ContactItem)o; 
        foreach (Outlook.ItemProperty property in contact.ItemProperties) 
        { 
         Console.WriteLine(property.Name + ": " + property.Value.ToString()); 
        } 
       } 
      } 
      Console.WriteLine("Press any key"); 
      Console.ReadKey(); 
     } 
    } 
} 

Hoffnung, das hilft.

- Frank

Verwandte Themen