【问题标题】:Exchange Web Services - How to retrieve a Contact using the Account extended propertyExchange Web 服务 - 如何使用 Account 扩展属性检索联系人
【发布时间】:2012-12-18 19:00:46
【问题描述】:

我正在使用 C# 和 Exchange Web 服务 API,但无法找到使用名为 Account 的扩展属性检索联系人的方法。我们使用这个字段来保存一个对内部开发系统有意义的整数。在 WebDAV 下,我们知道如何检索联系人,但需要一些帮助(希望是一个简短的示例或代码 sn-p)来演示如何执行此操作。

【问题讨论】:

    标签: exchangewebservices extended-properties


    【解决方案1】:

    我在约会中使用了扩展属性,所以它们的工作原理可能与联系人相同。

    这个想法是为约会放置一个 Guid,因为他们的本地 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;
    }
    

    【讨论】:

      【解决方案2】:

      不确定你是否还需要这个...但我刚刚解决了一些自己关闭的问题:

      我的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
                      ));
      }
      

      【讨论】:

        猜你喜欢
        • 2015-06-28
        • 1970-01-01
        • 2011-06-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-16
        • 2011-08-27
        • 1970-01-01
        相关资源
        最近更新 更多