/// <summary> /// The operation construct a request for FindItem operation. /// </summary> /// <param name="folderName">A string that specifies the folder to search.</param> /// <param name="value">A string that specifies the value for a search restriction.</param> /// <param name="field">A string that specifies the type of referenced field URI.</param> /// <returns>The request of FindItem operation which constructed with special folder name, search restriction and referenced field URI</returns> protected FindItemType ConstructFindItemRequest(string folderName, string value, string field) { FindItemType findRequest = new FindItemType(); findRequest.ItemShape = new ItemResponseShapeType(); findRequest.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties; DistinguishedFolderIdType folderId = new DistinguishedFolderIdType(); DistinguishedFolderIdNameType folderIdName; if (Enum.TryParse <DistinguishedFolderIdNameType>(folderName, out folderIdName)) { folderId.Id = folderIdName; } else { Site.Assert.Fail("The value of the first argument (foldIdNameType) of FindItem operation is invalid."); } findRequest.ParentFolderIds = new BaseFolderIdType[1]; findRequest.ParentFolderIds[0] = folderId; PathToUnindexedFieldType itemClass = new PathToUnindexedFieldType(); UnindexedFieldURIType fieldURI; if (Enum.TryParse <UnindexedFieldURIType>(field, out fieldURI)) { // set search field. itemClass.FieldURI = fieldURI; } else { Site.Assert.Fail("The value of the second argument (fieldURIType) of FindItem operation is invalid."); } ContainsExpressionType expressionType = new ContainsExpressionType(); expressionType.Item = itemClass; expressionType.ContainmentMode = ContainmentModeType.Substring; expressionType.ContainmentModeSpecified = true; expressionType.ContainmentComparison = ContainmentComparisonType.IgnoreCaseAndNonSpacingCharacters; expressionType.ContainmentComparisonSpecified = true; expressionType.Constant = new ConstantValueType(); expressionType.Constant.Value = value; RestrictionType restriction = new RestrictionType(); restriction.Item = expressionType; if (!string.IsNullOrEmpty(value)) { findRequest.Restriction = restriction; } return(findRequest); }
private static SetItemFieldType GetSubjectUpdate(Appointment apt) { SetItemFieldType subjectUpdate = new SetItemFieldType(); PathToUnindexedFieldType subjectPath = new PathToUnindexedFieldType(); subjectPath.FieldURI = UnindexedFieldURIType.itemSubject; CalendarItemType subjectData = new CalendarItemType(); subjectData.Subject = apt.Subject; subjectUpdate.Item = subjectPath; subjectUpdate.Item1 = subjectData; return(subjectUpdate); }
private static SetItemFieldType GetEndUpdate(Appointment apt) { SetItemFieldType endUpdate = new SetItemFieldType(); PathToUnindexedFieldType endPath = new PathToUnindexedFieldType(); endPath.FieldURI = UnindexedFieldURIType.calendarEnd; CalendarItemType endData = new CalendarItemType(); endData.End = apt.End; endData.EndSpecified = true; endUpdate.Item = endPath; endUpdate.Item1 = endData; return(endUpdate); }
private static SetItemFieldType GetStartUpdate(Appointment apt) { SetItemFieldType startUpdate = new SetItemFieldType(); PathToUnindexedFieldType startPath = new PathToUnindexedFieldType(); startPath.FieldURI = UnindexedFieldURIType.calendarStart; CalendarItemType startData = new CalendarItemType(); startData.Start = apt.Start; startData.StartSpecified = true; startUpdate.Item = startPath; startUpdate.Item1 = startData; return(startUpdate); }
/// <summary> /// Log on to a mailbox with a specified user account and find the specified folder then update the folder name of it. /// </summary> /// <param name="userName">Name of the user.</param> /// <param name="userPassword">Password of the user.</param> /// <param name="userDomain">Domain of the user.</param> /// <param name="parentFolderName">Name of the parent folder.</param> /// <param name="currentFolderName">Current name of the folder which will be updated.</param> /// <param name="newFolderName">New name of the folder which will be updated to.</param> /// <returns>If the name of the folder is updated successfully, return true; otherwise, return false.</returns> public bool FindAndUpdateFolderName(string userName, string userPassword, string userDomain, string parentFolderName, string currentFolderName, string newFolderName) { // Switch to specified user mailbox. bool isSwitched = AdapterHelper.SwitchUser(userName, userPassword, userDomain, this.exchangeServiceBinding, this.Site); Site.Assert.IsTrue( isSwitched, string.Format("Log on mailbox with the UserName: {0}, Password: {1}, Domain: {2} should be successful.", userName, userPassword, userDomain)); // Parse the parent folder name to DistinguishedFolderIdNameType. DistinguishedFolderIdNameType parentFolderIdName = (DistinguishedFolderIdNameType)Enum.Parse(typeof(DistinguishedFolderIdNameType), parentFolderName, true); // Create UpdateFolder request UpdateFolderType updateFolderRequest = new UpdateFolderType(); updateFolderRequest.FolderChanges = new FolderChangeType[1]; updateFolderRequest.FolderChanges[0] = new FolderChangeType(); updateFolderRequest.FolderChanges[0].Item = this.FindSubFolder(parentFolderIdName, currentFolderName); // Identify the field to update and the value to set for it. SetFolderFieldType displayName = new SetFolderFieldType(); PathToUnindexedFieldType displayNameProp = new PathToUnindexedFieldType(); displayNameProp.FieldURI = UnindexedFieldURIType.folderDisplayName; FolderType updatedFolder = new FolderType(); updatedFolder.DisplayName = newFolderName; displayName.Item = displayNameProp; updatedFolder.DisplayName = newFolderName; displayName.Item1 = updatedFolder; // Add a single element into the array of changes. updateFolderRequest.FolderChanges[0].Updates = new FolderChangeDescriptionType[1]; updateFolderRequest.FolderChanges[0].Updates[0] = displayName; bool isFolderNameUpdated = false; // Invoke the UpdateFolder operation and get the response. UpdateFolderResponseType updateFolderResponse = this.exchangeServiceBinding.UpdateFolder(updateFolderRequest); if (updateFolderResponse != null && ResponseClassType.Success == updateFolderResponse.ResponseMessages.Items[0].ResponseClass) { isFolderNameUpdated = true; } return(isFolderNameUpdated); }
private CalendarItemType GetOccurrenceItem(Appointment master, int index) { ItemIdType masterItemId = new ItemIdType(); masterItemId.Id = master.Attributes[ExchangeIdAttribute]; masterItemId.ChangeKey = master.Attributes[ExchangeChangeKeyAttribute]; OccurrenceItemIdType occurrenceItemId = new OccurrenceItemIdType(); occurrenceItemId.RecurringMasterId = masterItemId.Id; occurrenceItemId.InstanceIndex = index; PathToUnindexedFieldType calendarItemTypePath = new PathToUnindexedFieldType(); calendarItemTypePath.FieldURI = UnindexedFieldURIType.calendarCalendarItemType; GetItemType getItemRequest = new GetItemType(); getItemRequest.ItemShape = new ItemResponseShapeType(); getItemRequest.ItemShape.BaseShape = DefaultShapeNamesType.IdOnly; getItemRequest.ItemShape.AdditionalProperties = new BasePathToElementType[] { calendarItemTypePath }; getItemRequest.ItemIds = new BaseItemIdType[] { masterItemId, occurrenceItemId }; GetItemResponseType getItemResponse = Service.GetItem(getItemRequest); CalendarItemType occurrenceItem = null; foreach (ItemInfoResponseMessageType getItemResponseMessage in getItemResponse.ResponseMessages.Items) { if (getItemResponseMessage.ResponseClass == ResponseClassType.Success && getItemResponseMessage.Items.Items != null && getItemResponseMessage.Items.Items.Length > 0) { occurrenceItem = (CalendarItemType)getItemResponseMessage.Items.Items[0]; } } if (occurrenceItem == null) { throw new Exception("Unable to find occurrence"); } return(occurrenceItem); }
private static SetItemFieldType GetRecurrenceUpdate(Appointment apt) { SetItemFieldType recurrenceUpdate = new SetItemFieldType(); PathToUnindexedFieldType recurrencePath = new PathToUnindexedFieldType(); recurrencePath.FieldURI = UnindexedFieldURIType.calendarRecurrence; CalendarItemType recurrenceData = new CalendarItemType(); RecurrenceRule rrule; RecurrenceRule.TryParse(apt.RecurrenceRule, out rrule); if (rrule != null && rrule.Pattern.Frequency != RecurrenceFrequency.Hourly) { recurrenceData.Recurrence = CreateRecurrence(rrule, apt.Owner); } recurrenceUpdate.Item = recurrencePath; recurrenceUpdate.Item1 = recurrenceData; return(recurrenceUpdate); }
/// <summary> /// Generate UpdateItemRequest. /// </summary> /// <param name="createItemIds">The created item id.</param> /// <returns>Generated GetItemRequest.</returns> public static UpdateItemType GenerateUpdateItemRequest(params ItemIdType[] createItemIds) { // Specify needed to update value for the task item. TaskType taskUpdate = new TaskType { Companies = new string[] { "Company3", "Company4" } }; // Define the ItemChangeType element for updating the task item's companies. PathToUnindexedFieldType pathTo = new PathToUnindexedFieldType() { FieldURI = UnindexedFieldURIType.taskCompanies }; SetItemFieldType setItemField = new SetItemFieldType() { Item = pathTo, Item1 = taskUpdate }; ItemChangeType[] itemChanges = new ItemChangeType[createItemIds.Length]; for (int i = 0; i < createItemIds.Length; i++) { ItemChangeType itemChange = new ItemChangeType() { Item = createItemIds[i], Updates = new ItemChangeDescriptionType[] { setItemField } }; itemChanges[i] = itemChange; } // Return the UpdateItemType request to update the task item. return(new UpdateItemType() { ItemChanges = itemChanges, ConflictResolution = ConflictResolutionType.AlwaysOverwrite }); }
private void RemoveRecurrenceExceptions(Appointment appointmentToUpdate) { ItemChangeType itemUpdates = new ItemChangeType(); ItemIdType itemId = new ItemIdType(); itemId.Id = appointmentToUpdate.Attributes[ExchangeIdAttribute]; itemId.ChangeKey = appointmentToUpdate.Attributes[ExchangeChangeKeyAttribute]; itemUpdates.Item = itemId; PathToUnindexedFieldType deletedOccurrencesPath = new PathToUnindexedFieldType(); deletedOccurrencesPath.FieldURI = UnindexedFieldURIType.calendarRecurrence; DeleteItemFieldType deletedOccurrencesUpdate = new DeleteItemFieldType(); deletedOccurrencesUpdate.Item = deletedOccurrencesPath; // To reset the deleted and modified occurrences we must // remove the recurrence rule and then immediately restore it itemUpdates.Updates = new ItemChangeDescriptionType[] { deletedOccurrencesUpdate, GetRecurrenceUpdate(appointmentToUpdate) }; UpdateCalendarItem(new ItemChangeType[] { itemUpdates }); }
/// <summary> /// Log on to a mailbox with a specified user account and create a search folder. /// </summary> /// <param name="userName">Name of the user.</param> /// <param name="userPassword">Password of the user.</param> /// <param name="userDomain">Domain of the user.</param> /// <param name="searchFolderName">Name of the search folder.</param> /// <param name="searchText">Search text of the search folder.</param> /// <returns>If the search folder is created successfully, return true; otherwise, return false.</returns> public bool CreateSearchFolder(string userName, string userPassword, string userDomain, string searchFolderName, string searchText) { // Log on mailbox with specified user account(userName, userPassword, userDomain). bool isLoged = AdapterHelper.SwitchUser(userName, userPassword, userDomain, this.exchangeServiceBinding, this.Site); Site.Assert.IsTrue( isLoged, string.Format("Log on mailbox with the UserName: {0}, Password: {1}, Domain: {2} should be successful.", userName, userPassword, userDomain)); // Create the request. CreateFolderType createFolder = new CreateFolderType(); SearchFolderType[] folderArray = new SearchFolderType[1]; SearchFolderType searchFolder = new SearchFolderType(); // Use the following search filter to get all mail in the Inbox with the word searchText in the subject line. searchFolder.SearchParameters = new SearchParametersType(); searchFolder.SearchParameters.Traversal = SearchFolderTraversalType.Deep; searchFolder.SearchParameters.TraversalSpecified = true; searchFolder.SearchParameters.BaseFolderIds = new DistinguishedFolderIdType[4]; // Create a distinguished folder Identified of the inbox folder. DistinguishedFolderIdType inboxFolder = new DistinguishedFolderIdType(); inboxFolder.Id = new DistinguishedFolderIdNameType(); inboxFolder.Id = DistinguishedFolderIdNameType.inbox; searchFolder.SearchParameters.BaseFolderIds[0] = inboxFolder; DistinguishedFolderIdType contactType = new DistinguishedFolderIdType(); contactType.Id = new DistinguishedFolderIdNameType(); contactType.Id = DistinguishedFolderIdNameType.contacts; searchFolder.SearchParameters.BaseFolderIds[1] = contactType; DistinguishedFolderIdType calendarType = new DistinguishedFolderIdType(); calendarType.Id = new DistinguishedFolderIdNameType(); calendarType.Id = DistinguishedFolderIdNameType.calendar; searchFolder.SearchParameters.BaseFolderIds[2] = calendarType; DistinguishedFolderIdType taskType = new DistinguishedFolderIdType(); taskType.Id = new DistinguishedFolderIdNameType(); taskType.Id = DistinguishedFolderIdNameType.calendar; searchFolder.SearchParameters.BaseFolderIds[3] = taskType; // Use the following search filter. searchFolder.SearchParameters.Restriction = new RestrictionType(); PathToUnindexedFieldType path = new PathToUnindexedFieldType(); path.FieldURI = UnindexedFieldURIType.itemSubject; RestrictionType restriction = new RestrictionType(); FieldURIOrConstantType fieldURIORConstant = new FieldURIOrConstantType(); fieldURIORConstant.Item = new ConstantValueType(); (fieldURIORConstant.Item as ConstantValueType).Value = searchText; ExistsType isEqual = new ExistsType(); isEqual.Item = path; restriction.Item = isEqual; searchFolder.SearchParameters.Restriction = restriction; // Give the search folder a unique name. searchFolder.DisplayName = searchFolderName; folderArray[0] = searchFolder; // Create the search folder under the default Search Folder. TargetFolderIdType targetFolder = new TargetFolderIdType(); DistinguishedFolderIdType searchFolders = new DistinguishedFolderIdType(); searchFolders.Id = DistinguishedFolderIdNameType.searchfolders; targetFolder.Item = searchFolders; createFolder.ParentFolderId = targetFolder; createFolder.Folders = folderArray; bool isSearchFolderCreated = false; // Invoke CreateFolder operation and get the response. CreateFolderResponseType response = this.exchangeServiceBinding.CreateFolder(createFolder); if (response != null && ResponseClassType.Success == response.ResponseMessages.Items[0].ResponseClass) { // If the search folder is created successfully, return true; otherwise, return false. isSearchFolderCreated = true; searchFolder.FolderId = ((FolderInfoResponseMessageType)response.ResponseMessages.Items[0]).Folders[0].FolderId; AdapterHelper.CreatedFolders.Add(searchFolder); } return(isSearchFolderCreated); }
/// <summary> /// The method searches the mailbox and returns the items that meet a specified search restriction. /// </summary> /// <param name="folder">A string that specifies the folder to search.</param> /// <param name="value">A string that specifies the value for a search restriction.</param> /// <returns>If the method succeeds, return an array of item; otherwise, return null.</returns> private ItemIdType[] GetItemIds(string folder, string value) { #region Construct FindItem request FindItemType findRequest = new FindItemType(); if (string.IsNullOrEmpty(folder) || string.IsNullOrEmpty(value)) { Site.Assert.Fail("Invalid argument: one or more invalid arguments passed to GetItemIds method."); } findRequest.ItemShape = new ItemResponseShapeType(); findRequest.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties; DistinguishedFolderIdType folderId = new DistinguishedFolderIdType(); DistinguishedFolderIdNameType folderIdName; if (Enum.TryParse <DistinguishedFolderIdNameType>(folder, out folderIdName)) { folderId.Id = folderIdName; } else { Site.Assert.Fail("The value of the first argument (foldIdNameType) of FindItem operation is invalid."); } findRequest.ParentFolderIds = new BaseFolderIdType[1]; findRequest.ParentFolderIds[0] = folderId; PathToUnindexedFieldType itemClass = new PathToUnindexedFieldType(); itemClass.FieldURI = UnindexedFieldURIType.itemSubject; ContainsExpressionType expressionType = new ContainsExpressionType(); expressionType.Item = itemClass; expressionType.ContainmentMode = ContainmentModeType.Substring; expressionType.ContainmentModeSpecified = true; expressionType.ContainmentComparison = ContainmentComparisonType.IgnoreCaseAndNonSpacingCharacters; expressionType.ContainmentComparisonSpecified = true; expressionType.Constant = new ConstantValueType(); expressionType.Constant.Value = value; RestrictionType restriction = new RestrictionType(); restriction.Item = expressionType; findRequest.Restriction = restriction; #endregion #region Get the ids of all ItemId instances int counter = 0; int upperBound = int.Parse(Common.GetConfigurationPropertyValue("RetryCount", this.Site)); int waitTime = int.Parse(Common.GetConfigurationPropertyValue("WaitTime", this.Site)); FindItemResponseType findResponse = new FindItemResponseType(); while (counter < upperBound) { Thread.Sleep(waitTime); findResponse = this.exchangeServiceBinding.FindItem(findRequest); if (findResponse != null && findResponse.ResponseMessages != null && findResponse.ResponseMessages.Items != null && findResponse.ResponseMessages.Items.Length > 0) { ArrayOfRealItemsType items = ((FindItemResponseMessageType)findResponse.ResponseMessages.Items[0]).RootFolder.Item as ArrayOfRealItemsType; if (items.Items != null && items.Items.Length > 0) { List <ItemIdType> itemIds = new List <ItemIdType>(); foreach (ItemType item in items.Items) { if (item.ItemId != null) { itemIds.Add(item.ItemId); } } if (itemIds.Count > 0) { return(itemIds.ToArray()); } } } counter++; } Site.Log.Add(LogEntryKind.Debug, "When there is not any message found by FindItem operation, the retry count is {0}", counter); return(null); #endregion }
/// <summary> /// Выполняет поиск входящих писем с подтверждением об обработке файлов за указанный период /// </summary> /// <param name="begin">Дата начиная с которой будет происходить поиск писем</param> /// <returns></returns> public static ItemType[] GetMessages(DateTime begin) { ExchangeServiceBinding bind = new ExchangeServiceBinding(); bind.Credentials = new NetworkCredential(AppHelper.Configuration.Exchange.Username.GetDecryptedString(), AppHelper.Configuration.Exchange.Password.GetDecryptedString(), AppHelper.Configuration.Exchange.Domain); bind.Url = "https://" + AppHelper.Configuration.Exchange.ServerName + "/EWS/Exchange.asmx"; FindItemType findType = new FindItemType(); findType.Traversal = ItemQueryTraversalType.Shallow; findType.ItemShape = new ItemResponseShapeType(); findType.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties; DistinguishedFolderIdType folder = new DistinguishedFolderIdType(); folder.Id = DistinguishedFolderIdNameType.inbox; findType.ParentFolderIds = new BaseFolderIdType[] { folder }; IsEqualToType isEq = new IsEqualToType(); PathToUnindexedFieldType uPath = new PathToUnindexedFieldType(); uPath.FieldURI = UnindexedFieldURIType.messageFrom; FieldURIOrConstantType constType = new FieldURIOrConstantType(); ConstantValueType constValue = new ConstantValueType(); constValue.Value = AppHelper.Configuration.Exchange.SenderName; constType.Item = constValue; isEq.Item = uPath; isEq.FieldURIOrConstant = constType; IsGreaterThanOrEqualToType isGrEq = new IsGreaterThanOrEqualToType(); PathToUnindexedFieldType uPath2 = new PathToUnindexedFieldType(); uPath2.FieldURI = UnindexedFieldURIType.itemDateTimeSent; FieldURIOrConstantType constType2 = new FieldURIOrConstantType(); ConstantValueType constValue2 = new ConstantValueType(); constValue2.Value = string.Format("{0}-{1}-{2}T00:00:00Z", begin.Year, begin.Month.ToString("D2"), begin.Day.ToString("D2")); constType2.Item = constValue2; isGrEq.Item = uPath2; isGrEq.FieldURIOrConstant = constType2; AndType and = new AndType(); and.Items = new SearchExpressionType[] { isEq, isGrEq }; findType.Restriction = new RestrictionType(); findType.Restriction.Item = and; FindItemResponseType findResp = bind.FindItem(findType); FindItemResponseMessageType resMes = findResp.ResponseMessages.Items[0] as FindItemResponseMessageType; if (resMes.ResponseClass != ResponseClassType.Success) { throw new Exception("Ошибка при получении ответа от сервера Exchange:\n" + resMes.MessageText); } ItemType[] messages = (resMes.RootFolder.Item as ArrayOfRealItemsType).Items; return(messages); }
/// <summary> /// Finds all Calendar Items for the current User's Mailbox. /// </summary> /// <returns></returns> //protected internal CalendarItemType[] FindCalendarItems() //{ // // Identify which folders to search. // DistinguishedFolderIdType[] parentFolderIds = new DistinguishedFolderIdType[1]; // parentFolderIds[0] = new DistinguishedFolderIdType(); // parentFolderIds[0].Id = DistinguishedFolderIdNameType.calendar; // return FindCalendarItems(parentFolderIds); //} protected internal CalendarItemType[] FindCalendarItems(DistinguishedFolderIdType[] parentFolderIds) { // Form the FindItem request. FindItemType findItemRequest = new FindItemType(); // Define the item properties that are returned in the response. ItemResponseShapeType itemProperties = new ItemResponseShapeType(); itemProperties.BaseShape = DefaultShapeNamesType.IdOnly; PathToUnindexedFieldType calendarIsRecurringFieldPath = new PathToUnindexedFieldType(); calendarIsRecurringFieldPath.FieldURI = UnindexedFieldURIType.calendarIsRecurring; PathToUnindexedFieldType calendarItemTypeFieldPath = new PathToUnindexedFieldType(); calendarIsRecurringFieldPath.FieldURI = UnindexedFieldURIType.calendarCalendarItemType; PathToUnindexedFieldType calendarStartFieldPath = new PathToUnindexedFieldType(); calendarStartFieldPath.FieldURI = UnindexedFieldURIType.calendarStart; PathToUnindexedFieldType calendarEndFieldPath = new PathToUnindexedFieldType(); calendarEndFieldPath.FieldURI = UnindexedFieldURIType.calendarEnd; //location //PathToUnindexedFieldType calendarLocation = new PathToUnindexedFieldType(); //calendarLocation.FieldURI = UnindexedFieldURIType.calendarLocation; //// body //PathToUnindexedFieldType itemBody = new PathToUnindexedFieldType(); //itemBody.FieldURI = UnindexedFieldURIType.itemBody; itemProperties.AdditionalProperties = new PathToUnindexedFieldType[] { calendarIsRecurringFieldPath, calendarItemTypeFieldPath, calendarStartFieldPath, calendarEndFieldPath }; findItemRequest.ItemShape = itemProperties; findItemRequest.ParentFolderIds = parentFolderIds; // Define the sort order of items. FieldOrderType[] fieldsOrder = new FieldOrderType[1]; fieldsOrder[0] = new FieldOrderType(); PathToUnindexedFieldType subjectOrder = new PathToUnindexedFieldType(); subjectOrder.FieldURI = UnindexedFieldURIType.calendarStart; fieldsOrder[0].Item = subjectOrder; fieldsOrder[0].Order = SortDirectionType.Ascending; findItemRequest.SortOrder = fieldsOrder; // Define the traversal type. findItemRequest.Traversal = ItemQueryTraversalType.Shallow; // Send the FindItem request and get the response. FindItemResponseType findItemResponse = Service.FindItem(findItemRequest); // Access the response message. ArrayOfResponseMessagesType responseMessages = findItemResponse.ResponseMessages; ResponseMessageType responseMessage = responseMessages.Items[0]; if (responseMessage is FindItemResponseMessageType) { FindItemResponseMessageType firmt = (responseMessage as FindItemResponseMessageType); FindItemParentType fipt = firmt.RootFolder; object obj = fipt.Item; if (obj is ArrayOfRealItemsType) { ArrayOfRealItemsType items = (obj as ArrayOfRealItemsType); if (items.Items != null) { List <CalendarItemType> calendarItems = new List <CalendarItemType>(items.Items.Length); foreach (ItemType item in items.Items) { CalendarItemType calendarItem = item as CalendarItemType; if (calendarItem != null) { calendarItems.Add(calendarItem); } } return(calendarItems.ToArray()); } return(new CalendarItemType[0]); } } return(null); }
static FolderIdType FindFolder(ExchangeServiceBinding esb, DistinguishedFolderIdType fiFolderID, String fnFldName) { FolderIdType rvFolderID = new FolderIdType(); // Create the request and specify the travesal type FindFolderType findFolderRequest = new FindFolderType(); findFolderRequest.Traversal = FolderQueryTraversalType.Deep; // Define the properties returned in the response FolderResponseShapeType responseShape = new FolderResponseShapeType(); responseShape.BaseShape = DefaultShapeNamesType.Default; findFolderRequest.FolderShape = responseShape; // Identify which folders to search DistinguishedFolderIdType[] folderIDArray = new DistinguishedFolderIdType[1]; folderIDArray[0] = new DistinguishedFolderIdType(); folderIDArray[0].Id = fiFolderID.Id; //Add Restriction for DisplayName RestrictionType ffRestriction = new RestrictionType(); IsEqualToType ieToType = new IsEqualToType(); PathToUnindexedFieldType diDisplayName = new PathToUnindexedFieldType(); diDisplayName.FieldURI = UnindexedFieldURIType.folderDisplayName; FieldURIOrConstantType ciConstantType = new FieldURIOrConstantType(); ConstantValueType cvConstantValueType = new ConstantValueType(); cvConstantValueType.Value = fnFldName; ciConstantType.Item = cvConstantValueType; ieToType.Item = diDisplayName; ieToType.FieldURIOrConstant = ciConstantType; ffRestriction.Item = ieToType; findFolderRequest.Restriction = ffRestriction; // Add the folders to search to the request findFolderRequest.ParentFolderIds = folderIDArray; try { // Send the request and get the response FindFolderResponseType findFolderResponse = esb.FindFolder(findFolderRequest); // Get the response messages ResponseMessageType[] rmta = findFolderResponse.ResponseMessages.Items; foreach (ResponseMessageType rmt in rmta) { // Cast to the correct response message type FindFolderResponseMessageType ffResponse = (FindFolderResponseMessageType)rmt; foreach (FolderType fFoundFolder in ffResponse.RootFolder.Folders) { rvFolderID = fFoundFolder.FolderId; } } } catch (Exception e) { string problem = e.Message; } return rvFolderID; }