【问题标题】:Exchange Webservice Managed API - Find items by extended propertiesExchange Webservice Managed API - 按扩展属性查找项目
【发布时间】:2013-02-12 13:24:08
【问题描述】:

我曾尝试在 EWS 约会中使用扩展属性,但我似乎无法再次找到约会。设置属性部分等于这个问题中显示的部分:

How to Update an Appointment from Exchange Web Service Managed API 2.0 in ASP.NET

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

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

然后什么都没有找到。

【问题讨论】:

    标签: c# exchange-server exchangewebservices


    【解决方案1】:

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

    希望对你有帮助...

    【讨论】:

    • 欢迎您...也许下次您可以帮助我;)您能否设置“很有帮助”;)
    • 根据stackoverflow.com/questions/25187481/…,您应该始终使用自己的属性集ID,以避免与其他供应商设置的属性冲突。仍然喜欢您的快速解决方案!
    【解决方案2】:

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

    【讨论】:

    • 是的,我在错误的文件夹中搜索,但仍然没有找到:-/
    • 嗯...也许是因为您创建属性定义的方式。试试这个代码: ExtendedPropertyDefinition propdef = new ExtendedPropertyDefinition(Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet.PublicStrings, name, MapiPropertyType.String);用于添加和搜索。我在使用 Guid-way 时也遇到了一些问题。这个更简单,并且在我的代码中效果很好。
    【解决方案3】:

    这是一个将 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;
    } 
    

    【讨论】:

    • 这是我用来设置 Guid 的代码。第二部分从约会中检索 guid。我的问题是我需要在只有 Guid 的情况下找到具体的约会。
    • 好吧,当您找到从某些日期到其他日期的约会时,您可以使用您提取的 Guid 在它们之间应用 if 案例搜索,如果它匹配或不匹配。
    猜你喜欢
    • 2013-09-22
    • 2013-06-11
    • 2017-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-27
    • 1970-01-01
    相关资源
    最近更新 更多