枚举的Outlook ContactItem属性 [英] Enumerating Outlook ContactItem properties

查看:201
本文介绍了枚举的Outlook ContactItem属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想列举一个Microsoft.Office.Interop.Outlook.ContactItem对象的属性(我们称之为CI)与此代码:

I'm trying to enumerate the properties of an Microsoft.Office.Interop.Outlook.ContactItem object (let's call it ci) with this code:

        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值的几种组合,但没有属性是永远。返回

I've actually tried several combinations of BindingFlag values, but no properties are ever returned.

这是ContactItem是如何定义的:使用System.Runtime.InteropServices
;

This is how ContactItem is defined: using 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道具简单):

This is how _ContactItem is defined (I've kept only 3 props for simplicity):

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



有人能帮助我吗?

Could somebody help me?

在此先感谢

鲍勃

推荐答案

在不需要手动定义的接口。只为Microsoft Outlook中XX.0类库的引用添加到您的C#项目,然后用类似下面的代码:

you do not need to to define the interfaces manually. Just add a reference to "Microsoft Outlook XX.0 Class Library" to your C# project, and then use code similar to this:

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



希望这有助于。

Hope this helps.

- 弗兰克

这篇关于枚举的Outlook ContactItem属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆