2012-12-18 25 views
0

我正在使用C#和Exchange Web服務API,並且一直無法找到使用名爲Account的擴展屬性檢索聯繫人的方法。我們使用這個字段來保存一個整數,這對於內部開發的系統是有意義的。在WebDAV下,我們知道如何檢索聯繫人,但需要一些幫助(希望是一個簡短的示例或代碼片段)來演示如何執行此操作。Exchange Web Services - 如何使用帳戶擴展屬性檢索聯繫人

回答

0

我已經使用約會的擴展屬性,所以也許他們工作在與聯繫人相同的概念。

這個想法是爲約會提供指導,因爲他們的本地ID不是固定的。

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

不知道,如果你仍然需要這個......但我只是解決了一些接近自己:

answer 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 
       )); 
} 
相關問題