[英]Enumerating Outlook ContactItem properties
I'm trying to enumerate the properties of an Microsoft.Office.Interop.Outlook.ContactItem object (let's call it ci) with this code: 我试图使用以下代码枚举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);
}
I've actually tried several combinations of BindingFlag values, but no properties are ever returned. 我实际上尝试了几种BindingFlag值的组合,但是没有返回任何属性。
This is how ContactItem is defined: using System.Runtime.InteropServices; 这就是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
{
}
}
This is how _ContactItem is defined (I've kept only 3 props for simplicity): 这就是_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; }
}
}
Could somebody help me? 有人能帮助我吗?
Thanks in advance 提前致谢
Bob 短发
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: 只需在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();
}
}
}
Hope this helps. 希望这可以帮助。
-- Frank - 弗兰克
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.