簡體   English   中英

枚舉Outlook ContactItem屬性

[英]Enumerating Outlook ContactItem properties

我試圖使用以下代碼枚舉Microsoft.Office.Interop.Outlook.ContactItem對象的屬性(讓我們稱之為ci):

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

我實際上嘗試了幾種BindingFlag值的組合,但是沒有返回任何屬性。

這就是ContactItem的定義方式:使用System.Runtime.InteropServices;

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

這就是_ContactItem的定義方式(為簡單起見,我只保留了3個道具):

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

有人能幫助我嗎?

提前致謝

短發

您無需手動定義接口。 只需在C#項目中添加對“Microsoft Outlook XX.0類庫”的引用,然后使用與此類似的代碼:

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

希望這可以幫助。

- 弗蘭克

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM