繁体   English   中英

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

[英]Exchange Webservice Managed API - Find items by extended properties

我曾试图在与EWS的约会上使用扩展属性,但我似乎无法再次找到约会。 set属性部分等于此问题中显示的属性:

如何从ASP.NET中的Exchange Web Service托管API 2.0更新约会

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

http://msdn.microsoft.com/en-us/uc14trainingcourse_5l_topic3#_Toc254008129 http://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);

然后找不到任何东西。

这是一个示例代码,如何使用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;
} 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM