【问题标题】:Exchange web services: why is ItemId not constant? [continued]Exchange Web 服务:为什么 ItemId 不恒定? [继续]
【发布时间】:2012-08-03 08:34:43
【问题描述】:

正如其他人之前讨论过这个问题(例如,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);

因此,如果之前有人这样做过,他/她是否可以向我提供一个示例,即使应用程序退出,也可以将扩展属性标记在项目上。 谢谢

【问题讨论】:

  • 您好,“一旦应用程序重新启动,项目的扩展属性就会消失”到底是什么意思?
  • 我已经在下面的答案中回答了我自己的问题:)
  • 我知道。 :) 但是我也使用扩展属性,并且很好奇我存储在其中的值是否可能在某些时候丢失?
  • 我不这么认为。至少我没有再遇到这种情况了。

标签: c# exchangewebservices


【解决方案1】:

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

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;
} 

【讨论】:

  • 将此移植到 VB 以便在那里使用。用作: Dim guid As String = GetGuidForAppointment(appointment) If String.IsNullOrEmpty(guid) Then SetGuidForAppointment(appointment) guid = GetGuidForAppointment(appointment) End If
猜你喜欢
  • 2011-05-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多