Exchange Webservice Managed API -通过扩展属性查找项目

本文关键字:扩展 属性 查找 项目 -通 Webservice Managed API Exchange | 更新日期: 2023-09-27 18:01:29

我尝试在EWS的约会上使用扩展属性,但我似乎无法再次找到约会。set属性部分等于本题所示:

如何在ASP中从Exchange Web Service Managed API 2.0更新约会。净

当我尝试检索约会时,我遵循了以下示例:

http://msdn.microsoft.com/en-us/uc14trainingcourse_5l_topic3 _Toc254008129http://msdn.microsoft.com/en-us/library/exchange/dd633697 (v = exchg.80) . aspx

但是当我查找时,我从来没有得到任何返回的约会。

下面是查找的代码:
        ItemView view = new ItemView(10);
        // Get the GUID for the property set.
        Guid MyPropertySetId = new Guid("{" + cGuid + "}");
        // Create a definition for the extended property.
        ExtendedPropertyDefinition extendedPropertyDefinition =
          new ExtendedPropertyDefinition(MyPropertySetId, "AppointmentID", MapiPropertyType.String);
        view.PropertySet =
         new PropertySet(
               BasePropertySet.IdOnly,
               ItemSchema.Subject,
               AppointmentSchema.Start,
               AppointmentSchema.End, extendedPropertyDefinition);
        SearchFilter filter = new SearchFilter.Exists(extendedPropertyDefinition);
        FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, filter,
            view);

感谢您的帮助。

编辑:

当我尝试像文档所示的那样创建属性时:

http://msdn.microsoft.com/en-us/library/exchange/dd633654 (v = exchg.80) . aspx

它失败是因为它是一个Guid作为属性值添加。: -/

编辑:我试着获取今天所有的约会,并从我刚刚创建的约会中获取属性,它说的和我存储的一样,没有{},所以它必须是带有过滤器的东西。

再次编辑*它和

有关
 ExtendedPropertyDefinition extendedProperty = new ExtendedPropertyDefinition(

如果我使用:

 new ExtendedPropertyDefinition(
                DefaultExtendedPropertySet.Appointment,
                "AppointmentID",
                MapiPropertyType.String);

它找到所有具有属性的约会,但是如果我搜索一个特定的约会:

 Guid MyPropertySetId = new Guid("{" + cGuid + "}");
 ExtendedPropertyDefinition extendedProperty =
            new ExtendedPropertyDefinition(
                MyPropertySetId,
                "AppointmentID",
                MapiPropertyType.String);

Exchange Webservice Managed API -通过扩展属性查找项目

下面是如何使用customid创建约会并在保存后找到它的示例代码:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
        service.AutodiscoverUrl("someone@somewhere.com");
        ExtendedPropertyDefinition def = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "AppointmenId", MapiPropertyType.String);
        Guid testid = Guid.NewGuid ();
        Appointment appointment = new Appointment(service);
        appointment.Subject = "Test";
        appointment.Start = DateTime.Now.AddHours(1);
        appointment.End = DateTime.Now.AddHours(2);
        appointment.SetExtendedProperty(def, testid.ToString());
        appointment.Save(WellKnownFolderName.Calendar);
        SearchFilter filter = new SearchFilter.IsEqualTo(def, testid.ToString());
        FindItemsResults<Item> fir = service.FindItems(WellKnownFolderName.Calendar, filter, new ItemView(10));

在收件箱中搜索约会。在那里你永远找不到他们。请尝试在日历中搜索。

下面是一个将guid作为扩展属性并根据guid获取约会的示例。

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