正如其他人之前讨论过这个问题(例如Exchange web services: why is ItemId not constant?)一样,我想谈一谈解决方案,我已经完成了将Guid标记为扩展属性的建议,对我来说,这种解决方案是不错的(尽管我确实不知道如何使其与出现的情况一起使用),但只有在应用程序正常工作后,应用程序重新启动后,项目的扩展属性才会消失,所以我现在的问题是“如何在EWS项目上标记扩展属性并使其不断在那里?
这是更新日历项目(约会)的代码

public void SetGuidForAppointement(Appointment appointment)
{
appointment.SetExtendedProperty((ExtendedPropertyDefinition)_appointementIdPropertyDefinition, Guid.NewGuid().ToString());
appointment.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToNone);
}
这些是上面需要的属性定义。
_appointementIdPropertyDefinition = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Appointment, "AppointmentID", MapiPropertyType.String);
            _propertyDefinitionBases = new PropertyDefinitionBase[] { _appointementIdPropertyDefinition, ItemSchema.ParentFolderId, AppointmentSchema.Start, AppointmentSchema.End,
AppointmentSchema.LegacyFreeBusyStatus, AppointmentSchema.Organizer };
            PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, _propertyDefinitionBases);
因此,如果有人以前做过此事,他/她可以为我提供一个示例,即使应用程序退出,该示例仍将扩展属性标记在项目上。
谢谢

最佳答案

经过一段时间的尝试和搜索,我已经找到解决问题的方法。

private static readonly PropertyDefinitionBase AppointementIdPropertyDefinition = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "AppointmentID", MapiPropertyType.String);
public static PropertySet PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, AppointementIdPropertyDefinition);


//Setting the property for the appointment
 public static void SetGuidForAppointement(Appointment appointment)
{
    try
    {
        appointment.SetExtendedProperty((ExtendedPropertyDefinition)AppointementIdPropertyDefinition, Guid.NewGuid().ToString());
        appointment.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToNone);
    }
    catch (Exception ex)
    {
        // logging the exception
    }
}

//Getting the property for the appointment
 public static string GetGuidForAppointement(Appointment appointment)
{
    var result = "";
    try
    {
        appointment.Load(PropertySet);
        foreach (var extendedProperty in appointment.ExtendedProperties)
        {
            if (extendedProperty.PropertyDefinition.Name == "AppointmentID")
            {
                result = extendedProperty.Value.ToString();
            }
        }
    }
    catch (Exception ex)
    {
     // logging the exception
    }
    return result;
}

关于c# - Exchange Web服务: why is ItemId not constant? [续],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11827152/

10-13 06:17