【问题标题】:EWS Create Appointment in exchange with extra custom propertiesEWS 创建约会以换取额外的自定义属性
【发布时间】:2014-07-02 22:07:03
【问题描述】:

我目前正在寻找一种使用 C# 将一些额外属性保存到交换约会的方法。目前我可以使用以下属性进行保存:

Appointment calendar = new Appointment(p_service);

calendar.Subject = calendarS5Subject;
calendar.Body = calendarS5Body;
calendar.Start = calendarS5StartDateTime;
calendar.End = calendarS5EndDateTime;
calendar.IsReminderSet = false;
calendar.Location = calendarS5Location;
calendar.Body.BodyType = BodyType.Text;

calendar.Save();

但是我希望能够存储我自己的自定义属性,例如 calendar.EventID 和 calendar.Blah 。是否可以根据约会保存这些属性,然后以后可以访问它们?如果可以将其全部存储为指定窗口内的用户控件表单,那就更好了。我知道您可以通过使用 AppointmentItem 类型的 Outlook 插件来做到这一点。但是,我还没有找到一种方法来使用 Appointment 类型进行交换。

TIA。

我现在可以使用以下方法保存额外的属性:

Guid EventIDSetGUID = new Guid("{C11FF724-AA03-4555-9952-8FA248A11C3E}");
ExtendedPropertyDefinition extendedPropertyEventID = new ExtendedPropertyDefinition(EventIDSetGUID, "EventID", MapiPropertyType.String);
calendar.SetExtendedProperty(extendedPropertyEventID, calendarS5EventID);

但是,我现在很难稍后再读回该属性。这项工作在我保存了额外的属性之后,但如果我重新启动应用程序然后尝试读取额外的属性eventIDProp 总是返回null。我的阅读代码:

Guid EventIDReadGUID = new Guid("{C11FF724-AA03-4555-9952-8FA248A11C3E}");
ExtendedPropertyDefinition extendedPropertyEventIDRead = new ExtendedPropertyDefinition(EventIDReadGUID, "EventID", MapiPropertyType.String);
object eventIDProp;
if (calendar.TryGetProperty(extendedPropertyEventIDRead, out eventIDProp) && eventIDProp != calendarS5EventID)
{

}

【问题讨论】:

    标签: c# visual-studio-2012 exchange-server exchangewebservices


    【解决方案1】:

    您可以使用 MAPI 扩展属性做到这一点:

        // Define MAPI extended properties
        private readonly ExtendedPropertyDefinition _extendedPropEventId = 
            new ExtendedPropertyDefinition(
                new Guid("{00020329-0000-0000-C000-000000000046}"),
                "Event Identifier",
                MapiPropertyType.String);
    
        private readonly ExtendedPropertyDefinition _extendedPropBlah = 
            new ExtendedPropertyDefinition(
                new Guid("{00020329-0000-0000-C000-000000000046}"),
                "Blah",
                MapiPropertyType.String);
    
    ...
    
        // Set extended properties for appointment
        calendar.SetExtendedProperty(_extendedPropEventId, "custom EventID value");
        calendar.SetExtendedProperty(_extendedPropBlah, "custom Blah value");
    
    ...
    
        // Bind to existing item for reading extended properties
        var propertySet = new PropertySet(BasePropertySet.FirstClassProperties, _extendedPropEventId, _extendedPropBlah);
        var calendar = Appointment.Bind(p_service, itemId, propertySet);
        if (calendar.ExtendedProperties.Any(ep => ep.PropertyDefinition.PropertySetId == _extendedPropEventId.PropertySetId))
        {
            // Add your code here...
        }
    

    【讨论】:

    • 我也刚刚在网上找到了这个,到目前为止,我已经能够使用类似于您的示例的东西来保存它们,但是我现在正在努力从约会中读取属性。请参阅我的原始帖子编辑:)
    • 我已成功使用具有特定 Guid“{00020329-0000-0000-C000-000000000046}”的自定义属性,包括写入和读取。根据KB907985:“您在 Outlook 自定义表单上使用的 Outlook 自定义字段或属性都具有 GUID {00020329-0000-0000-C000-000000000046}。在 MAPI 中,GUID 称为 PS_PULIC_STRINGS。但是,自定义 MAPI 程序可能有自己的自定义属性 GUID。"
    • 我刚刚查看了旧代码,发现您需要在绑定约会项时指定您的属性集。查看我的更新答案:-)
    • 那太好了,谢谢你,我会试一试,如果可行,我会给你答案:)
    猜你喜欢
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-02
    • 2014-05-23
    • 1970-01-01
    相关资源
    最近更新 更多