6

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.

Community
  • 1
  • 1
Jacob
  • 409
  • 1
  • 6
  • 16

3 Answers3

22

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

Jürgen Hoffmann
  • 947
  • 4
  • 15
  • your welcome... maybe next time you can help me ;) can you please set the "was helpfull" ;) – Jürgen Hoffmann Feb 28 '13 at 15:35
  • According to http://stackoverflow.com/questions/25187481/should-i-use-guid-or-defaultextendedpropertyset-publicstrings-while-constructing you should always use your own property set id, to avoid collision with properties set by other vendors. Still love your quick solution! – Stephan Mar 03 '16 at 21:39
0

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

Jürgen Hoffmann
  • 947
  • 4
  • 15
  • Yes, I was searching in the wrong folder, but it still finds nothing :-/ – Jacob Feb 27 '13 at 11:54
  • hmm... maybe it's because of the way how your create your propertydefinition. try this code: ExtendedPropertyDefinition propdef = new ExtendedPropertyDefinition(Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet.PublicStrings, name, MapiPropertyType.String); for adding and searching. I had some Problems using the Guid-way too. This one is easier and works perferct in my code. – Jürgen Hoffmann Feb 27 '13 at 13:39
0

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;
} 
Ahmad ElMadi
  • 2,507
  • 21
  • 36
  • This is the code I am using for setting the Guid. The second part retrieves the guid from an appointment. My problem is I need to find the specific appointment when only having the Guid. – Jacob Feb 27 '13 at 18:07
  • well, when you find the appointments from certain dates to others, then you apply an if case searching among them using the Guid which you extract if it matches or not. – Ahmad ElMadi Feb 28 '13 at 12:00