EWS:同一个 public 文件夹每个用户有不同的 UniqueIDs?
EWS: Same public folder has different UniqueIDs per user?
我遇到了一个奇怪的问题:当我查看同一个文件夹(在 Exchange 2010 的 Public 文件夹上)时,我得到了两个不同用户的两个不同的 UniqueID:
ID 似乎既包含用户特定部分,也包含公共部分。如何将它们识别为同一文件夹?
编辑:在某些系统上,文件夹的 FolderID.UniqueID 对于所有用户都是相同的。
这实际上是使用 EWS Managed API 的人面临的一个非常普遍的问题。
由于某些原因(我不知道为什么)当约会被移动到另一个文件夹时,唯一 ID 发生了变化。
所以你可以尝试设置一个ExtendesPropertyDefinition
,你在其中为你正在处理的文件夹声明你的GUID / UniqueID,每次你做folder.update
或 appointment.update
(如果是约会),您可以将 extendedPropertyDefinition
传递给 update()
方法。
只需将下面的代码与您的文件夹一起使用(将约会替换为文件夹,这应该会以某种方式起作用:))
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;
}
我建议您使用 PR_SOURCE_KEY 扩展 属性 而不是 https://msdn.microsoft.com/en-us/library/ee178895(v=exchg.80).aspx 这将始终与 public 文件夹保持一致,您也可以使用 属性 在 MAPI 中访问 Outlook 插件中的文件夹
干杯
格伦
我遇到了一个奇怪的问题:当我查看同一个文件夹(在 Exchange 2010 的 Public 文件夹上)时,我得到了两个不同用户的两个不同的 UniqueID:
ID 似乎既包含用户特定部分,也包含公共部分。如何将它们识别为同一文件夹?
编辑:在某些系统上,文件夹的 FolderID.UniqueID 对于所有用户都是相同的。
这实际上是使用 EWS Managed API 的人面临的一个非常普遍的问题。
由于某些原因(我不知道为什么)当约会被移动到另一个文件夹时,唯一 ID 发生了变化。
所以你可以尝试设置一个ExtendesPropertyDefinition
,你在其中为你正在处理的文件夹声明你的GUID / UniqueID,每次你做folder.update
或 appointment.update
(如果是约会),您可以将 extendedPropertyDefinition
传递给 update()
方法。
只需将下面的代码与您的文件夹一起使用(将约会替换为文件夹,这应该会以某种方式起作用:))
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;
}
我建议您使用 PR_SOURCE_KEY 扩展 属性 而不是 https://msdn.microsoft.com/en-us/library/ee178895(v=exchg.80).aspx 这将始终与 public 文件夹保持一致,您也可以使用 属性 在 MAPI 中访问 Outlook 插件中的文件夹
干杯 格伦