Exchange Web 服务:为什么 ItemId 不是常量?[续]
本文关键字:常量 服务 Web 为什么 ItemId Exchange | 更新日期: 2024-10-25 12:50:16
正如其他人之前讨论过这个问题一样(例如,Exchange Web 服务:为什么 ItemId 不是常量?),我想谈谈解决方案,我已经通过将 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;
}