EWS-扩展属性搜索 [英] EWS - Extended Property Search
问题描述
大家好,
我尝试了多种方法来搜索日历约会中的扩展属性,但没有成功.我正在使用VS 2008中的C#(Web服务).请问指向正确的方向吗?
[edit]
我有一个VSTO应用程序,该应用程序将Guid放入每个约会用户属性中.当使用EWS时,我想检索该资源/会议室的所有扩展属性.我正在使用C#(Web服务项目),VS2008和Exchange2010.因此,首先可以这样做吗?如果是这样,我该如何实现呢?
[edit]
通过执行以下操作,我确实获得了资源中所有约会的列表,但是当我调用ExtendedProperty时,每个属性的值都为null,并且我知道其中两个项目都有值.
Hi all,
I have tried various ways to search for extended properties within calendar appointment, without any success. I am making use of C# (Web Services), VS 2008. Can any please point me in the right direction?
[edit]
I have a VSTO application that puts a Guid into each Appointment user property. When by making use of EWS I want to retrieve all the Extended Properties for that resource / boardroom. I am making use of C# (Web Service Project), VS2008 and Exchange 2010. So, first of all, is it possible to do this? And if so, how can I achieve this?
[edit]
I do get a list of all appointment within the resource by performing the following, but when I call the ExtendedProperty the value is null for each one, and I know for two of the items there are values.
foreach (ItemType it in items.Items)
{
if (it is CalendarItemType)
{
CalendarItemType cal = (CalendarItemType)it;
if (cal.ExtendedProperty != null)
tmp.Add(new ExtendedAppointmentData()
{
EndDate = cal.End,
StartDate = cal.Start,
EventID = new Guid(cal.ExtendedProperty[0].Item.ToString()),
AppointmentStatus = cal.LegacyFreeBusyStatus.ToString()
});
}
}
提前非常感谢.
亲切的问候,
Many thanks in advance.
Kind regards,
推荐答案
以下代码转储"解决了我的问题(仔细研究了属性DistinguishedPropertySetType.PublicStrings带来了很大的不同!) :
The following ''code dump'' solved my problem (have a close look at the property DistinguishedPropertySetType.PublicStrings made a world of difference!!):
<br />
<pre><br />
/// <summary><br />
/// Gets the all calendar data as well as extended property data of a specific resource mailbox.<br />
/// </summary><br />
/// <param name="mailbox">The specified resource mailbox - boardroom email address.</param><br />
/// <param name="startDate">The start date of the calendar view.</param><br />
/// <param name="endDate">The end date of the calendar view.</param><br />
/// <param name="boardRoomID">The board room ID.</param><br />
/// <returns><br />
/// returns a collection of appointments related as well as the extended property data to the specified resource mailbox<br />
/// </returns><br />
/// <exception cref="System.Exception">Represents errors that occur during application execution.</exception><br />
public List<ExtendedAppointmentData> GetExtendedPropertyData(string mailbox, DateTime startDate, DateTime endDate, string boardRoomID)<br />
{<br />
if (Convert.ToBoolean(ConfigurationManager.AppSettings["remotecertificatevalidation"]))<br />
ServicePointManager.ServerCertificateValidationCallback =<br />
delegate(Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)<br />
{<br />
return true;<br />
};<br />
ExchangeServiceBinding esb = new ExchangeServiceBinding();<br />
esb.Url = ConfigurationManager.AppSettings["exchangeService2010"];<br />
esb.Credentials = new NetworkCredential("test", "password", "domain.local");<br />
List<ExtendedAppointmentData> tmp = new List<ExtendedAppointmentData>();<br />
// Form the FindItem request.<br />
FindItemType findItemRequest = new FindItemType();<br />
CalendarViewType calendarView = new CalendarViewType();<br />
calendarView.StartDate = startDate;<br />
calendarView.EndDate = endDate;<br />
calendarView.MaxEntriesReturned = 100;<br />
calendarView.MaxEntriesReturnedSpecified = true;<br />
findItemRequest.Item = calendarView;<br />
// Define which item properties are returned in the response.<br />
ItemResponseShapeType itemProperties = new ItemResponseShapeType();<br />
// Use the Default shape for the response.<br />
//itemProperties.BaseShape = DefaultShapeNamesType.IdOnly;<br />
itemProperties.BaseShape = DefaultShapeNamesType.AllProperties;<br />
findItemRequest.ItemShape = itemProperties;<br />
DistinguishedFolderIdType[] folderIDArray = new DistinguishedFolderIdType[1];<br />
folderIDArray[0] = new DistinguishedFolderIdType();<br />
folderIDArray[0].Id = DistinguishedFolderIdNameType.calendar;<br />
folderIDArray[0].Mailbox = new EmailAddressType();<br />
folderIDArray[0].Mailbox.EmailAddress = mailbox;<br />
findItemRequest.ParentFolderIds = folderIDArray;<br />
// Define the traversal type.<br />
findItemRequest.Traversal = ItemQueryTraversalType.Shallow;<br />
try<br />
{<br />
// Send the FindItem request and get the response.<br />
FindItemResponseType findItemResponse = esb.FindItem(findItemRequest);<br />
// Access the response message.<br />
ArrayOfResponseMessagesType responseMessages = findItemResponse.ResponseMessages;<br />
ResponseMessageType[] rmta = responseMessages.Items;<br />
int folderNumber = 0;<br />
foreach (ResponseMessageType rmt in rmta)<br />
{<br />
// One FindItemResponseMessageType per folder searched.<br />
FindItemResponseMessageType firmt = rmt as FindItemResponseMessageType;<br />
if (firmt.RootFolder == null)<br />
continue;<br />
FindItemParentType fipt = firmt.RootFolder;<br />
object obj = fipt.Item;<br />
// FindItem contains an array of items.<br />
if (obj is ArrayOfRealItemsType)<br />
{<br />
ArrayOfRealItemsType items = (obj as ArrayOfRealItemsType);<br />
if (items.Items == null)<br />
folderNumber++;<br />
else<br />
{<br />
foreach (ItemType it in items.Items)<br />
{<br />
if (it is CalendarItemType)<br />
{<br />
CalendarItemType cal = (CalendarItemType)it;<br />
ExtendedPropertyType[] extendedProperties = GetExtendedProperties(cal.ItemId, esb);<br />
if (extendedProperties != null)<br />
tmp.Add(new ExtendedAppointmentData()<br />
{<br />
EndDate = cal.End.ToLocalTime(),<br />
StartDate = cal.Start.ToLocalTime(),<br />
EventID = extendedProperties[0].Item.ToString(),<br />
AppointmentStatus = cal.LegacyFreeBusyStatus.ToString(),<br />
BoardroomID = boardRoomID,<br />
FreeBusyInfo = this.GetFreeBusyTimes2010(30, mailbox, startDate, endDate, esb)<br />
});<br />
}<br />
}<br />
folderNumber++;<br />
}<br />
}<br />
}<br />
return tmp;<br />
}<br />
catch<br />
{<br />
throw;<br />
}<br />
}<br />
/// <summary><br />
/// Gets the extended properties of a resource / boardroom.<br />
/// </summary><br />
/// <param name="itemID">The item ID.</param><br />
/// <param name="serviceBinding">The exchange service binding.</param><br />
/// <returns><br />
/// returns an array of extended properties; otherwise null if none existed<br />
/// </returns><br />
private ExtendedPropertyType[] GetExtendedProperties(ItemIdType itemID, ExchangeServiceBinding serviceBinding)<br />
{<br />
PathToExtendedFieldType pathClassification = new PathToExtendedFieldType();<br />
pathClassification.DistinguishedPropertySetId = DistinguishedPropertySetType.PublicStrings;<br />
pathClassification.DistinguishedPropertySetIdSpecified = true;<br />
pathClassification.PropertyName = STR_Guid;<br />
pathClassification.PropertyType = MapiPropertyTypeType.String;<br />
<br />
GetItemType getExPropertiesRequest = new GetItemType();<br />
ItemIdType iiItemId = new ItemIdType();<br />
iiItemId = itemID;<br />
ItemResponseShapeType getResponseShape = new ItemResponseShapeType();<br />
getResponseShape.BaseShape = DefaultShapeNamesType.AllProperties;<br />
getResponseShape.IncludeMimeContent = true;<br />
getExPropertiesRequest.ItemShape = getResponseShape;<br />
getExPropertiesRequest.ItemShape.AdditionalProperties = new BasePathToElementType[1];<br />
getExPropertiesRequest.ItemShape.AdditionalProperties[0] = pathClassification;<br />
<br />
getExPropertiesRequest.ItemIds = new ItemIdType[1];<br />
getExPropertiesRequest.ItemIds[0] = iiItemId;<br />
getExPropertiesRequest.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties;<br />
GetItemResponseType giResponse = serviceBinding.GetItem(getExPropertiesRequest);<br />
if (giResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Error)<br />
{<br />
return null;<br />
}<br />
else<br />
{<br />
ItemInfoResponseMessageType rmResponseMessage = giResponse.ResponseMessages.Items[0] as ItemInfoResponseMessageType;<br />
MessageType message = rmResponseMessage.Items.Items[0] as MessageType; <br />
//return (message.ExtendedProperty);<br />
return (rmResponseMessage.Items.Items[0].ExtendedProperty);<br />
}<br />
}<br />
</pre><br />
亲切的问候,
Kind regards,
这篇关于EWS-扩展属性搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!