0

I am using C# and the Exchange Web Services API and have been unable to find a way to retrieve a contact using the extended property named Account. We have used this field to hold an integer number that is meaningful to an in-house developed system. Under WebDAV, we knew how to retrieve the Contact but need some help (hopefully a short example or code snippet) to demonstrate how to do this.

Bill Mitchell
  • 161
  • 1
  • 4

2 Answers2

0

I have used extended property with appointments, so maybe they work on the same concept as the contacts.

The Idea is to put a Guid for appointments as their native IDs are not constant.

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
0

Not sure if you still need this... but I just solved something close myself:

My answer here should be in the ballpark of what you want. I'm using a boolean as well as Account here:

ExchangeService service = this.GetService(); // my method to build service
FolderId folderID = GetPublicFolderID(service, "My Address Book"); 
ContactsFolder folder = ContactsFolder.Bind(service, folderID);
int folderCount = folder.TotalCount;

var guid       = DefaultExtendedPropertySet.PublicStrings;
var epdAccount = new ExtendedPropertyDefinition(0x3A00, MapiPropertyType.String);
var epdCID     = new ExtendedPropertyDefinition(0x3A4A, MapiPropertyType.String);
var epdCBLN    = new ExtendedPropertyDefinition(guid, "CustomBln", MapiPropertyType.Boolean);
var epdCDBL    = new ExtendedPropertyDefinition(guid, "CustomDbl", MapiPropertyType.Double);

var view = new ItemView(folderCount);
view.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties);
view.PropertySet.Add(epdAccount);
view.PropertySet.Add(epdCID);
view.PropertySet.Add(epdCBLN);
view.PropertySet.Add(epdCDBL);  

//var searchOrFilterCollection = new List<SearchFilter>();
//searchOrFilterCollection.Add(new SearchFilter.IsEqualTo(epdCBLN, true));
//searchOrFilterCollection.Add(new SearchFilter.IsEqualTo(epdAccount, "user"));
//var filter = new SearchFilter.SearchFilterCollection(LogicalOperator.And, searchOrFilterCollection);

var filter = new SearchFilter.IsEqualTo(epdAccount, "user");
var contacts = service.FindItems(folderID, filter, view);

foreach (Contact contact in contacts)
{
    string Account;
    int  CID;
    bool CBLN;
    double CDBL;

    contact.GetLoadedPropertyDefinitions();
    contact.TryGetProperty(epdAccuont, out Account);
    contact.TryGetProperty(epdCID, out CID);
    contact.TryGetProperty(epdCBLN, out CBLN);
    contact.TryGetProperty(epdCDBL, out CDBL);

    Console.WriteLine(String.Format("{0, -20} - {1} - {2} - {3} - {4}"
                    , contact.DisplayName
                    , contact.EmailAddresses[EmailAddressKey.EmailAddress1]
                    , Account
                    , CID
                    , CBLN
                    , CDBL
                ));
}
Community
  • 1
  • 1
WernerCD
  • 2,137
  • 6
  • 31
  • 51