我怎样才能获取/设置从联系人使用微软的EWS API扩展属性?微软、属性、联系人、EWS

2023-09-03 06:21:30 作者:佩服许仙敢曰蛇

我想我创造它正确,就像下面这样。 c是一个联系,而我只是想存储的唯一标识符考虑到这是由EWS提供ITEMID心不是静态的......

  propertySetId = System.Guid.NewGuid();
//创建扩展属性的定义。
ExtendedPropertyDefinition extendedPropertyDefinition =新ExtendedPropertyDefinition(DefaultExtendedPropertySet.Common,itemGUID,MapiPropertyType.String);
c.SetExtendedProperty(extendedPropertyDefinition,propertySetId.ToString());
c.Update(ConflictResolutionMode.AlwaysOverwrite);
 

当我试图拉这回出基于别的东西联系人搜索时,如名字,我得到一个空返回。我试图通过获得的值:

 的foreach(在findResults.Items C项)
{
      的foreach(ExtendedProperty extendedProperty在c.ExtendedProperties)
      {
            如果(extendedProperty.PropertyDefinition.Name ==itemGUID)
            {
                  结果[I] = extendedProperty.Value.ToString();
            }
      }
}
 

编辑:$ C $下findResults

 名单,其中,SearchFilter> sea​​rchFilters =新的名单,其中,SearchFilter>();
sea​​rchFilters.Add(新SearchFilter.IsEqualTo(itemGUID,值));
//可以多个过滤器在这里视情况
SearchFilter过滤器=新SearchFilter.SearchFilterCollection(LogicalOperator.And,searchFilters.ToArray());
findResults = service.FindItems(WellKnownFolderName.Contacts,过滤器,查看);
 
Oppo紧急联系人怎么设置 Oppo紧急联系人怎么用方法

解决方案

您需要分配属性集 ItemView控件告诉EWS什么样的属性,当你搜索使用 FindItems 包括。如果不包括在您的 ItemView控件也不会提供reading.The另一种方法是使用 Contact.Bind 并要求财产问题每个联系人(更多的服务请求,但有时需要的)。

请参阅查看使用EWS 有关使用扩展属性在EWS。

办法#1:检索扩展属性对所有联系人的

ExtendedPropertyDefinition propDef =新ExtendedPropertyDefinition(DefaultExtendedPropertySet.Common,itemGUID,MapiPropertyType.String); ItemView控件视图=新ItemView控件(50){属性集=新的属性集(propDef)};

方法2:如果你有一个Contact ID的的

绑定一个接触的时间

ExtendedPropertyDefinition propDef =新ExtendedPropertyDefinition(DefaultExtendedPropertySet.Common,itemGUID,MapiPropertyType.String); 联系方式联系方式= Contact.Bind(服务的ContactID,新的属性集(propDef));

I think I'm creating it properly, like as follows. c is a Contact, and I'm just trying to store a unique identifier considering that ItemId which is provided by EWS isnt static...

propertySetId = System.Guid.NewGuid();
// Create a definition for the extended property.
ExtendedPropertyDefinition extendedPropertyDefinition = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Common, "itemGUID", MapiPropertyType.String);
c.SetExtendedProperty(extendedPropertyDefinition, propertySetId.ToString());
c.Update(ConflictResolutionMode.AlwaysOverwrite);

When I try to pull this back out when searching for the contact based on something else, like first name, I'm getting a null returned. I'm trying to get the value by:

foreach (Item c in findResults.Items)
{
      foreach(ExtendedProperty extendedProperty in c.ExtendedProperties)
      {
            if(extendedProperty.PropertyDefinition.Name == "itemGUID")
            {
                  results[i] = extendedProperty.Value.ToString();
            }
      }
}

EDIT: code for findResults

List<SearchFilter> searchFilters = new List<SearchFilter>();
searchFilters.Add(new SearchFilter.IsEqualTo(itemGUID, value));
//can be more filters here depending on situation
SearchFilter filter = new SearchFilter.SearchFilterCollection(LogicalOperator.And, searchFilters.ToArray());
findResults = service.FindItems(WellKnownFolderName.Contacts, filter, view);

解决方案

You need to assign the PropertySet in the ItemView to tell EWS what properties to include when you search using FindItems. If you don't include it in your ItemView it won't be available for reading.The alternative approach is to use the Contact.Bind and request the property for each Contact in question (more service requests, but sometimes necessary).

See Viewing Extended Properties using EWS for a full example on working with Extended Properties in EWS.

Approach #1: Retrieve Extended Property for all Contacts

ExtendedPropertyDefinition propDef = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Common, "itemGUID", MapiPropertyType.String);
ItemView view = new ItemView(50) { PropertySet = new PropertySet(propDef) };

Approach #2: Bind one contact at a time if you have a Contact ID

ExtendedPropertyDefinition propDef = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Common, "itemGUID", MapiPropertyType.String);
Contact contact = Contact.Bind(service, contactID, new PropertySet(propDef));