简体   繁体   中英

Trying to find an EWS appointment using an Extended Property

I am trying to find an appointment using the Global UID. I know what the Global UID will be ahead of time (it can be set when you create the appointment).

I created the ExtendedPropertyDefinition by referencing this URL http://msdn.microsoft.com/en-us/library/cc815676(v=office.15).aspx .

        var service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
        service.Credentials = new NetworkCredential("","","");
        service.Url = new Uri("");
        ExtendedPropertyDefinition epICalId = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Appointment, 3, MapiPropertyType.String);
        ItemView view = new ItemView(50);
        view.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties);
        view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Descending);
        FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Calendar, new SearchFilter.IsEqualTo(epICalId, "CustomUID123"), view);
        var x = findResults.TotalCount;

The problem is that no meetings are returned. Any ideas?

I still cannot convert the ICalUID to the binary object. It may be that it is a different object (see comments below). But I can set up a search filter with the Extended property. In the code below I simply save off the "temp" object and re-use it for search.

        var PROP_DEF_PidLidGlobalObjectId = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Meeting, 0x00000003, MapiPropertyType.Binary);
        appt.Load(new PropertySet(BasePropertySet.FirstClassProperties, PROP_DEF_PidLidGlobalObjectId);
        object temp;
        appt.TryGetProperty(PROP_DEF_PidLidGlobalObjectId, out temp);
        var sf2 = new SearchFilter.IsEqualTo(PROP_DEF_PidLidGlobalObjectId, Convert.ToBase64String(temp as byte[]));

You're using the wrong MapiPropertyType. The GlobalID is a binary property, not a string. EWS handles these in SOAP with Base64 strings. I believe extended properties of the binary type will come through as a byte array, so if you're getting/setting a binary extended property, you may need to handle the Base64 conversion yourself if need be. If you already have the Base64 string, then no problem. Define the extended property as binary and use the Base64 string in the search filter. EWS should do the rest.

Ah, I'm sorry, I missed it. You're checking in DefaultExtendedPropertySet.Appointment. It should be DefaultExtendedPropertySet.Meeting instead. If you're trying to set the Global Unique ID that way then you're setting a "new" extended property instead. You cannot set the GlobalUniqueID. Exchange may not throw an error if you try, but that doesn't mean that it did what you asked it to do. The GlobalUniqueID is generated based on the date/time of the Appointment. It may match the ICalUID (I was unaware before that they could match, so apologies), but not necessarily. Look at the differences between GlobalUniqueID and CleanGlobalUniqueID. I don't know if the ICalUID itself can be set separate from that, but I doubt it. If you want to search on any of these, you'll need to create the Appointment, then load the extended properties you want and retain them elsewhere for searching or set your own extended property with your own identifier and search on that.

I believe the problem is that your PropertySet doesn't include your ExtendedPropertyDefinition. So when you're calling FindItemsResults there are no extended property values loaded to search through. So change:

view.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties); 

to

view.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, epICalId); 

Viewing custom extended properties by using the EWS Managed API is a good resource if that doesn't fix it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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