Exchange Webservice Managed API - Find items by extended properties

前端 未结 3 882
抹茶落季
抹茶落季 2021-01-12 19:57

I have tried to use extended properties on appointments with EWS, but I can not seem to find the appointments again. The set property part is equal to the one shown in this

相关标签:
3条回答
  • 2021-01-12 20:15

    here's a samplecode how to create an appointment with the customid and find it after saving:

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

    hope this helps you...

    0 讨论(0)
  • 2021-01-12 20:19

    You search the inbox for appointments. There you will never find them. Try to search in the Calendar instead.

    0 讨论(0)
  • 2021-01-12 20:25

    Here is an example of putting the guid as extension property and getting the appointment based on the 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;
    } 
    
    0 讨论(0)
提交回复
热议问题