Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exchange Webservice Managed API - Find items by extended properties

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 question:

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

When I try to retrieve the appointment, I have followed these examples:

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

But I never get any appointments returned when I make a lookup.

Here is the code for the lookup:

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

Any help is greatly appreciated.

Edit: When I try to create the property like the documentation shows:

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

It fails because its a Guid im adding as property value. :-/

Edit again: Just tried getting all appointments for today, and getting the property from the appointment I just created, and it says the same as I stored, without the {}, so it must be somthing with the filter.

Edit once again* It has somthing to do with

 ExtendedPropertyDefinition extendedProperty = new ExtendedPropertyDefinition(

if I use:

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

It finds all the appointments with properties, but if I search for a specific one:

 Guid MyPropertySetId = new Guid("{" + cGuid + "}");

 ExtendedPropertyDefinition extendedProperty =
            new ExtendedPropertyDefinition(
                MyPropertySetId,
                "AppointmentID",
                MapiPropertyType.String);

Then nothing is found.

like image 825
Jacob Avatar asked Feb 26 '13 22:02

Jacob


1 Answers

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("[email protected]");

        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...

like image 60
Jürgen Hoffmann Avatar answered Oct 22 '22 00:10

Jürgen Hoffmann