从 EWS 访问 Outlook 用户属性

发布于 2024-11-25 12:19:44 字数 641 浏览 1 评论 0原文

我正在尝试创建一个使用 EWS api 访问联系人的应用程序。

我需要在此过程中查看 Outlook 用户属性之一,但我不知道如何使用 EWS 获取它。目前我刚刚尝试过...

service.Url = new Uri("https://url/ews/Exchange.asmx");
service.Credentials = new WebCredentials("credentials");
var results = service.FindItems(folderId, new ItemView(100));
foreach (var item in results)
{
     Contact contact = item as Contact;
     foreach (var prop in contact.ExtendedProperties)
     {
            Console.WriteLine(prop.Value.ToString());
     }
}

编译和执行没有问题,但对于每个联系人,ExtendProperties 计数为 0,在 Outlook 中约为 30。

那么我怎样才能获得我正在寻找的属性呢?

仅供参考。我正在使用 exhcnage 2007。

谢谢。

I'm trying to create an application that use the EWS api to access contacts.

I need to look at one of the outlook user properties in this process but I cant see how to get it at using EWS. At the moment ive just tried...

service.Url = new Uri("https://url/ews/Exchange.asmx");
service.Credentials = new WebCredentials("credentials");
var results = service.FindItems(folderId, new ItemView(100));
foreach (var item in results)
{
     Contact contact = item as Contact;
     foreach (var prop in contact.ExtendedProperties)
     {
            Console.WriteLine(prop.Value.ToString());
     }
}

Which compiles and executes without a problem, but for every contact the ExtendedProperties count is 0 which in outlook its about 30.

So how can I get the properties I'm looking for?

Just an FYI. Im using exhcnage 2007.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

骄傲 2024-12-02 12:19:44

您需要定义想要获取的属性 - EWS 不允许您枚举用户属性。

Userproperties 位于命名空间 PublicStrings 中。

private static readonly ExtendedPropertyDefinition CustomProperty = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "MyCustomProperty", MapiPropertyType.String);

然后,您可以在 FindItems 请求中使用该定义:

var items = service.FindItems(WellKnownFolderName.Inbox, new ItemView(100) { PropertySet =   new PropertySet(BasePropertySet.FirstClassProperties, CustomProperty)});

You need to define the properties you want to get - EWS does not permit you to enumerate user properties.

The Userproperties are in the namespace PublicStrings.

private static readonly ExtendedPropertyDefinition CustomProperty = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "MyCustomProperty", MapiPropertyType.String);

You can then use the definition in a FindItems request:

var items = service.FindItems(WellKnownFolderName.Inbox, new ItemView(100) { PropertySet =   new PropertySet(BasePropertySet.FirstClassProperties, CustomProperty)});
半葬歌 2024-12-02 12:19:44

我也遇到同样的问题,解决了。

var customProp1 = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings,
                        "myCustomPropOne", MapiPropertyType.String);

var customProp2 = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings,
                      "myCustomPropTwo", MapiPropertyType.String);

var userFields = new ExtendedPropertyDefinition[] { customProp1, customProp2 };

var extendedPropertySet = new PropertySet(BasePropertySet.FirstClassProperties, userFields);

var contactItems = service.FindItems(WellKnownFolderName.Contacts, new ItemView(100)
            { PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, extendedPropertySet) });
// Looping contacts
    foreach (Item item in contactItems){
        object firstProp;              
        if (item.TryGetProperty(customProp1, out firstProp) && firstProp != null)
        {
               var val = firstProp.ToString();
        }
        object secondProp;
        if (item.TryGetProperty(customProp2, out secondProp) && secondProp != null)
        {
               var val = secondProp.ToString();
        }
     } // loop ends

myCustomPropOne & myCustomPropTwo 是您在 Outlook/editor 中设置的用户定义属性的名称。 参考

I had the same problem, solved.

var customProp1 = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings,
                        "myCustomPropOne", MapiPropertyType.String);

var customProp2 = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings,
                      "myCustomPropTwo", MapiPropertyType.String);

var userFields = new ExtendedPropertyDefinition[] { customProp1, customProp2 };

var extendedPropertySet = new PropertySet(BasePropertySet.FirstClassProperties, userFields);

var contactItems = service.FindItems(WellKnownFolderName.Contacts, new ItemView(100)
            { PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, extendedPropertySet) });
// Looping contacts
    foreach (Item item in contactItems){
        object firstProp;              
        if (item.TryGetProperty(customProp1, out firstProp) && firstProp != null)
        {
               var val = firstProp.ToString();
        }
        object secondProp;
        if (item.TryGetProperty(customProp2, out secondProp) && secondProp != null)
        {
               var val = secondProp.ToString();
        }
     } // loop ends

myCustomPropOne & myCustomPropTwo are names of user defined properties you set in outlook/editor. ref

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文