Esempio n. 1
0
        public FolderIdType FindFolderID(ExchangeServiceBinding service, DistinguishedFolderIdNameType folder)
        {
            FindFolderType requestFindFolder = new FindFolderType();

            requestFindFolder.Traversal = FolderQueryTraversalType.Deep;

            DistinguishedFolderIdType[] folderIDArray = new DistinguishedFolderIdType[1];
            folderIDArray[0]    = new DistinguishedFolderIdType();
            folderIDArray[0].Id = folder;

            FolderResponseShapeType itemProperties = new FolderResponseShapeType();

            itemProperties.BaseShape = DefaultShapeNamesType.AllProperties;

            requestFindFolder.ParentFolderIds = folderIDArray;
            requestFindFolder.FolderShape     = itemProperties;
            //requestFindFolder.FolderShape.BaseShape = DefaultShapeNamesType.AllProperties;


            FindFolderResponseType objFindFolderResponse = service.FindFolder(requestFindFolder);

            foreach (ResponseMessageType responseMsg in objFindFolderResponse.ResponseMessages.Items)
            {
                if (responseMsg.ResponseClass == ResponseClassType.Success)
                {
                    FindFolderResponseMessageType objFindResponse = responseMsg as FindFolderResponseMessageType;

                    foreach (BaseFolderType objFolderType in objFindResponse.RootFolder.Folders)
                    {
                        return(objFolderType.FolderId);
                    }
                }
            }
            return(null);
        }
        public BaseFolderType GetRootFolder()
        {
            var binding = ChannelHelper.BuildChannel(hostname, username, password);

            var findFolderType = new FindFolderType
            {
                Traversal       = FolderQueryTraversalType.Shallow,
                ParentFolderIds = new[] { new DistinguishedFolderIdType {
                                              Id = DistinguishedFolderIdNameType.root
                                          } },
                FolderShape = new FolderResponseShapeType {
                    BaseShape = DefaultShapeNamesType.AllProperties
                }
            };

            var findFolderResponse = binding.FindFolder(findFolderType);

            if (findFolderResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Error)
            {
                throw new Exception(findFolderResponse.ResponseMessages.Items[0].MessageText);
            }

            BaseFolderType[] bft = ((FindFolderResponseMessageType)findFolderResponse.ResponseMessages.Items[0]).RootFolder.Folders;

            return(bft[0]);
        }
        /// <summary>
        /// Returns all folders in the exchange box.
        /// </summary>
        /// <returns></returns>
        public IEnumerable <BaseFolderType> FindAllFolders(string id)
        {
            var binding = ChannelHelper.BuildChannel(hostname, username, password);

            var findFolderType = new FindFolderType
            {
                Traversal       = FolderQueryTraversalType.Shallow,
                ParentFolderIds = new[] { new FolderIdType {
                                              Id = id
                                          } },
                FolderShape = new FolderResponseShapeType {
                    BaseShape = DefaultShapeNamesType.AllProperties
                }
            };

            FindFolderResponseType findFolderResponse = binding.FindFolder(findFolderType);

            if (findFolderResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Error)
            {
                throw new Exception(findFolderResponse.ResponseMessages.Items[0].MessageText);
            }

            var folders = ((FindFolderResponseMessageType)findFolderResponse.ResponseMessages.Items[0]).RootFolder.Folders;

            foreach (var baseFolderType in folders)
            {
                yield return(baseFolderType);

                // Find children of current folder
                foreach (var folderType in FindAllFolders(baseFolderType.FolderId.Id))
                {
                    yield return(folderType);
                }
            }
        }
        /// <summary>
        /// Find all the sub folders in the specified folder.
        /// </summary>
        /// <param name="parentFolderName">Name of the specified parent folder.</param>
        /// <returns>An array of found sub folders.</returns>
        private BaseFolderType[] FindAllSubFolders(DistinguishedFolderIdNameType parentFolderName)
        {
            // Create an array of BaseFolderType.
            BaseFolderType[] folders = null;

            // Create the request and specify the traversal type.
            FindFolderType findFolderRequest = new FindFolderType();

            findFolderRequest.Traversal = FolderQueryTraversalType.Deep;

            // Define the properties to be 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 = parentFolderName;

            // Add the folders to search to the request.
            findFolderRequest.ParentFolderIds = folderIDArray;

            FindFolderResponseType        findFolderResponse            = this.exchangeServiceBinding.FindFolder(findFolderRequest);
            FindFolderResponseMessageType findFolderResponseMessageType = new FindFolderResponseMessageType();

            if (findFolderResponse != null && findFolderResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success)
            {
                findFolderResponseMessageType = findFolderResponse.ResponseMessages.Items[0] as FindFolderResponseMessageType;
                folders = findFolderResponseMessageType.RootFolder.Folders;
            }

            return(folders);
        }
Esempio n. 5
0
        // Token: 0x0600057E RID: 1406 RVA: 0x0002A21C File Offset: 0x0002841C
        public BaseFolderType GetFolderByName(BaseFolderIdType parentFolderId, string folderDisplayName, BasePathToElementType[] additionalProperties)
        {
            FindFolderType          findFolder = new FindFolderType();
            FolderResponseShapeType folderResponseShapeType = new FolderResponseShapeType();

            folderResponseShapeType.BaseShape            = DefaultShapeNamesType.IdOnly;
            folderResponseShapeType.AdditionalProperties = additionalProperties;
            findFolder.FolderShape = folderResponseShapeType;
            findFolder.Restriction = new RestrictionType
            {
                Item = new IsEqualToType
                {
                    Item = new PathToUnindexedFieldType
                    {
                        FieldURI = UnindexedFieldURIType.folderDisplayName
                    },
                    FieldURIOrConstant = new FieldURIOrConstantType
                    {
                        Item = new ConstantValueType
                        {
                            Value = folderDisplayName
                        }
                    }
                }
            };
            findFolder.ParentFolderIds = new BaseFolderIdType[]
            {
                parentFolderId
            };
            List <BaseFolderType> folders = new List <BaseFolderType>(1);

            this.CallService(() => this.ServiceBinding.FindFolder(findFolder), delegate(ResponseMessageType responseMessage, int messageIndex)
            {
                if (responseMessage.ResponseClass == ResponseClassType.Error)
                {
                    if (responseMessage.ResponseCode != ResponseCodeType.ErrorItemNotFound)
                    {
                        folders.Clear();
                        throw new RetryException(new ElcEwsException(ElcEwsErrorType.FailedToGetFolderByName, responseMessage.ResponseCode.ToString() + " : " + responseMessage.MessageText), false);
                    }
                }
                else
                {
                    FindFolderResponseMessageType findFolderResponseMessageType = (FindFolderResponseMessageType)responseMessage;
                    folders.AddRange(findFolderResponseMessageType.RootFolder.Folders);
                }
                return(true);
            }, (Exception exception) => ElcEwsClient.WrapElcEwsException(ElcEwsErrorType.FailedToGetFolderByName, exception));
            if (folders.Count <= 0)
            {
                return(null);
            }
            return(folders[0]);
        }
Esempio n. 6
0
        // Token: 0x0600057C RID: 1404 RVA: 0x00029EF4 File Offset: 0x000280F4
        public IEnumerable <BaseFolderType> GetFolderHierarchy(BaseFolderIdType parentFolderId, bool isDeepTraversal, BasePathToElementType[] additionalProperties)
        {
            List <BaseFolderType>   folderList = new List <BaseFolderType>();
            FindFolderType          findFolder = new FindFolderType();
            FolderResponseShapeType folderResponseShapeType = new FolderResponseShapeType();

            folderResponseShapeType.BaseShape            = DefaultShapeNamesType.IdOnly;
            folderResponseShapeType.AdditionalProperties = additionalProperties;
            findFolder.FolderShape     = folderResponseShapeType;
            findFolder.ParentFolderIds = new BaseFolderIdType[]
            {
                parentFolderId
            };
            findFolder.Traversal = (isDeepTraversal ? FolderQueryTraversalType.Deep : FolderQueryTraversalType.Shallow);
            bool morePage = true;
            int  offset   = 0;

            while (morePage)
            {
                findFolder.Item = new IndexedPageViewType
                {
                    BasePoint = IndexBasePointType.Beginning,
                    Offset    = offset
                };
                this.CallService(() => this.ServiceBinding.FindFolder(findFolder), delegate(ResponseMessageType responseMessage, int messageIndex)
                {
                    FindFolderResponseMessageType findFolderResponseMessageType = (FindFolderResponseMessageType)responseMessage;
                    if (responseMessage.ResponseClass == ResponseClassType.Error)
                    {
                        throw new RetryException(new ElcEwsException(ElcEwsErrorType.FailedToGetFolderHierarchy, responseMessage.ResponseCode.ToString() + " : " + responseMessage.MessageText), false);
                    }
                    folderList.AddRange(findFolderResponseMessageType.RootFolder.Folders);
                    if (findFolderResponseMessageType.RootFolder.IncludesLastItemInRange || !findFolderResponseMessageType.RootFolder.IncludesLastItemInRangeSpecified)
                    {
                        morePage = false;
                    }
                    else
                    {
                        offset = findFolderResponseMessageType.RootFolder.IndexedPagingOffset;
                    }
                    return(false);
                }, (Exception exception) => ElcEwsClient.WrapElcEwsException(ElcEwsErrorType.FailedToGetFolderHierarchy, exception));
            }
            return(folderList);
        }
 /// <remarks/>
 public void FindFolderAsync(FindFolderType FindFolder1, object userState)
 {
     if ((this.FindFolderOperationCompleted == null))
     {
         this.FindFolderOperationCompleted = new System.Threading.SendOrPostCallback(this.OnFindFolderOperationCompleted);
     }
     this.InvokeAsync("FindFolder", new object[] {
                 FindFolder1}, this.FindFolderOperationCompleted, userState);
 }
 /// <remarks/>
 public void FindFolderAsync(FindFolderType FindFolder1)
 {
     this.FindFolderAsync(FindFolder1, null);
 }
 /// <remarks/>
 public System.IAsyncResult BeginFindFolder(FindFolderType FindFolder1, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("FindFolder", new object[] {
                 FindFolder1}, callback, asyncState);
 }
Esempio n. 10
0
        /// <summary>
        /// Log on to a mailbox with a specified user account and delete all the subfolders from the specified 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="folderName">Name of the folder which should be cleaned up.</param>
        /// <param name="destFolderName">The name of the destination folder which will be deleted.</param>
        /// <returns>If the folder is cleaned up successfully, return true; otherwise, return false.</returns>
        public bool CleanupFolder(string userName, string userPassword, string userDomain, string folderName, string destFolderName)
        {
            // Log on mailbox with specified user mailbox.
            this.exchangeServiceBinding.Credentials = new NetworkCredential(userName, userPassword, userDomain);
            #region Delete all sub folders and the items in these sub folders in the specified parent folder.
            // Parse the parent folder name.
            DistinguishedFolderIdNameType parentFolderName = (DistinguishedFolderIdNameType)Enum.Parse(typeof(DistinguishedFolderIdNameType), folderName, true);

            // Create an array of BaseFolderType.
            BaseFolderType[] folders = null;

            // Create the request and specify the traversal type.
            FindFolderType findFolderRequest = new FindFolderType();
            findFolderRequest.Traversal = FolderQueryTraversalType.Deep;

            // Define the properties to be 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 = parentFolderName;

            // Add the folders to search to the request.
            findFolderRequest.ParentFolderIds = folderIDArray;

            // Invoke FindFolder operation and get the response.
            FindFolderResponseType findFolderResponse = this.exchangeServiceBinding.FindFolder(findFolderRequest);

            // If there are folders found under the specified folder, delete all of them.
            if (findFolderResponse != null && findFolderResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success)
            {
                // Get the folders from the response.
                FindFolderResponseMessageType findFolderResponseMessageType = findFolderResponse.ResponseMessages.Items[0] as FindFolderResponseMessageType;
                Site.Assert.IsNotNull(findFolderResponseMessageType, "The items in FindFolder response should not be null.");

                folders = findFolderResponseMessageType.RootFolder.Folders;
                if (folders.Length != 0)
                {
                    ////Indicates whether the destination folder was found and removed.
                    bool found = false;

                    // Loop to delete all the found folders.
                    foreach (BaseFolderType currentFolder in folders)
                    {
                        if (string.Compare(currentFolder.DisplayName, destFolderName, StringComparison.InvariantCultureIgnoreCase) != 0)
                        {
                            continue;
                        }

                        FolderIdType responseFolderId = currentFolder.FolderId;

                        FolderIdType folderId = new FolderIdType();
                        folderId.Id = responseFolderId.Id;

                        DeleteFolderType deleteFolderRequest = new DeleteFolderType();
                        deleteFolderRequest.DeleteType   = DisposalType.HardDelete;
                        deleteFolderRequest.FolderIds    = new BaseFolderIdType[1];
                        deleteFolderRequest.FolderIds[0] = folderId;

                        // Invoke DeleteFolder operation and get the response.
                        DeleteFolderResponseType deleteFolderResponse = this.exchangeServiceBinding.DeleteFolder(deleteFolderRequest);

                        Site.Assert.AreEqual <ResponseClassType>(
                            ResponseClassType.Success,
                            deleteFolderResponse.ResponseMessages.Items[0].ResponseClass,
                            "The delete folder operation should be successful.");

                        found = true;
                        break;
                    }

                    Site.Assert.IsTrue(
                        found,
                        "The destination folder can not be found in the assigned parent folder.");
                }
            }
            #endregion

            #region Check whether sub folders are deleted successfully.
            // Invoke the FindFolder operation again.
            findFolderResponse = this.exchangeServiceBinding.FindFolder(findFolderRequest);

            Site.Assert.AreEqual <ResponseCodeType>(
                ResponseCodeType.NoError,
                findFolderResponse.ResponseMessages.Items[0].ResponseCode,
                string.Format(
                    "The delete folder operation should be successful. Expected response code: {0}, actual response code: {1}",
                    ResponseCodeType.NoError,
                    findFolderResponse.ResponseMessages.Items[0].ResponseCode));

            // Get the found folders from the response.
            FindFolderResponseMessageType findFolderResponseMessage = findFolderResponse.ResponseMessages.Items[0] as FindFolderResponseMessageType;
            folders = findFolderResponseMessage.RootFolder.Folders;

            // If no sub folders that created by case could be found, the folder has been cleaned up successfully.
            foreach (BaseFolderType folder in folders)
            {
                if (string.Compare(folder.DisplayName, destFolderName, StringComparison.InvariantCultureIgnoreCase) != 0)
                {
                    continue;
                }
                else
                {
                    return(false);
                }
            }

            return(true);

            #endregion
        }
Esempio n. 11
0
        private static void Process(string username, string password, string folderName)
        {
            Console.WriteLine(" > Opening file...");

            var path  = Directory.GetCurrentDirectory() + @"\Leebl.csv";
            var leads = new LeadCollection(path);

            var binding = new ExchangeServiceBinding
            {
                Url         = "https://amxprd0510.outlook.com/ews/exchange.asmx",
                Credentials = new NetworkCredential(username, password),
                RequestServerVersionValue = new RequestServerVersion {
                    Version = ExchangeVersionType.Exchange2010
                }
            };

            #region Get folder

            Console.WriteLine(" > Retrieving folder...");

            var folderRequest = new FindFolderType
            {
                Traversal   = FolderQueryTraversalType.Deep,
                FolderShape = new FolderResponseShapeType {
                    BaseShape = DefaultShapeNamesType.IdOnly
                },
                ParentFolderIds = new BaseFolderIdType[]
                {
                    new DistinguishedFolderIdType {
                        Id = DistinguishedFolderIdNameType.root
                    }
                },
                Restriction = new RestrictionType
                {
                    Item = new ContainsExpressionType
                    {
                        ContainmentMode                = ContainmentModeType.Substring,
                        ContainmentModeSpecified       = true,
                        ContainmentComparison          = ContainmentComparisonType.IgnoreCase,
                        ContainmentComparisonSpecified = true,
                        Item = new PathToUnindexedFieldType
                        {
                            FieldURI = UnindexedFieldURIType.folderDisplayName
                        },
                        Constant = new ConstantValueType
                        {
                            Value = folderName
                        }
                    }
                }
            };

            var folderResponse = binding.FindFolder(folderRequest);
            var folderIds      = new List <BaseFolderIdType>();

            foreach (var folder in folderResponse.ResponseMessages.Items
                     .Select(x => (x as FindFolderResponseMessageType))
                     .Where(x => x != null))
            {
                folderIds.AddRange(folder.RootFolder.Folders.Select(y => y.FolderId));
            }

            #endregion

            #region Get items

            Console.WriteLine(" > Retrieving items...");

            var itemRequest = new FindItemType
            {
                Traversal = ItemQueryTraversalType.Shallow,
                ItemShape = new ItemResponseShapeType {
                    BaseShape = DefaultShapeNamesType.Default
                },
                ParentFolderIds = folderIds.ToArray()
            };

            var itemResponse = binding.FindItem(itemRequest);
            var itemIds      = new List <BaseItemIdType>();

            foreach (var item in itemResponse.ResponseMessages.Items
                     .Select(x => (x as FindItemResponseMessageType))
                     .Where(x => x != null)
                     .Where(x => x.RootFolder != null && x.RootFolder.TotalItemsInView > 0))
            {
                itemIds.AddRange(((ArrayOfRealItemsType)item.RootFolder.Item).Items.Select(y => y.ItemId));
            }

            #endregion

            #region Get bodies

            Console.WriteLine(" > Parsing " + itemIds.Count + " messages...");

            var messageRequest = new GetItemType
            {
                ItemShape = new ItemResponseShapeType {
                    BaseShape = DefaultShapeNamesType.AllProperties
                },
                ItemIds = itemIds.ToArray()
            };

            var messageResponse = binding.GetItem(messageRequest);

            foreach (var message in messageResponse.ResponseMessages.Items
                     .Select(x => (x as ItemInfoResponseMessageType))
                     .Where(x => x != null)
                     .Select(x => x.Items.Items[0])
                     .Where(x => x != null))
            {
                leads.Add(message.Body.Value, message.DateTimeSent);
            }

            #endregion

            Console.WriteLine(" > Saving to file...");
            leads.Save(path);
        }
Esempio n. 12
0
    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;
    }
Esempio n. 13
0
        public BaseFolderType[] GetSubFolders(BaseFolderIdType parentFolderId, FolderResponseShapeType folderShape)
        {
            if (folderShape == null)
            {
                folderShape = EwsAuditClient.DefaultFolderShape;
            }
            IndexedPageViewType pageView = new IndexedPageViewType
            {
                Offset    = 0,
                BasePoint = IndexBasePointType.Beginning,
                MaxEntriesReturnedSpecified = true,
                MaxEntriesReturned          = 256
            };
            FindFolderType findFolderType = new FindFolderType
            {
                FolderShape     = folderShape,
                Item            = pageView,
                ParentFolderIds = new BaseFolderIdType[]
                {
                    parentFolderId
                },
                Traversal = FolderQueryTraversalType.Shallow
            };
            HashSet <string>      hashSet = null;
            List <BaseFolderType> list    = null;
            bool haveMore;

            do
            {
                findFolderType.Item = pageView;
                BaseFolderType[] localFoldersList = null;
                haveMore = false;
                this.CallEwsWithRetries((LID)43196U, () => this.binding.FindFolder(findFolderType), delegate(ResponseMessageType responseMessage, int messageIndex)
                {
                    FindFolderResponseMessageType findFolderResponseMessageType = responseMessage as FindFolderResponseMessageType;
                    if (findFolderResponseMessageType != null && findFolderResponseMessageType.ResponseClass == ResponseClassType.Success && findFolderResponseMessageType.RootFolder != null)
                    {
                        localFoldersList = findFolderResponseMessageType.RootFolder.Folders;
                        haveMore         = !findFolderResponseMessageType.RootFolder.IncludesLastItemInRange;
                        if (haveMore)
                        {
                            pageView.Offset = findFolderResponseMessageType.RootFolder.IndexedPagingOffset;
                        }
                        return(true);
                    }
                    return(false);
                }, null);
                if (localFoldersList != null && localFoldersList.Length > 0)
                {
                    foreach (BaseFolderType baseFolderType in localFoldersList)
                    {
                        if (baseFolderType != null && baseFolderType.FolderId != null && !string.IsNullOrEmpty(baseFolderType.FolderId.Id))
                        {
                            if (hashSet == null)
                            {
                                hashSet = new HashSet <string>();
                            }
                            else if (hashSet.Contains(baseFolderType.FolderId.Id))
                            {
                                goto IL_18B;
                            }
                            if (list == null)
                            {
                                list = new List <BaseFolderType>(localFoldersList.Length);
                            }
                            hashSet.Add(baseFolderType.FolderId.Id);
                            list.Add(baseFolderType);
                        }
                        IL_18B :;
                    }
                }
            }while (haveMore);
            if (list != null && list.Count > 0)
            {
                return(list.ToArray());
            }
            return(Array <BaseFolderType> .Empty);
        }
Esempio n. 14
0
        public bool FindFolder(string folderName, BaseFolderIdType parentFolderId, out FolderIdType folderId)
        {
            folderId = null;
            FindFolderType findFolderType = new FindFolderType
            {
                FolderShape = new FolderResponseShapeType
                {
                    BaseShape = DefaultShapeNamesType.IdOnly
                },
                Item = new IndexedPageViewType
                {
                    Offset    = 0,
                    BasePoint = IndexBasePointType.Beginning
                },
                ParentFolderIds = new BaseFolderIdType[]
                {
                    parentFolderId
                },
                Traversal   = FolderQueryTraversalType.Shallow,
                Restriction = new RestrictionType
                {
                    Item = new IsEqualToType
                    {
                        Item = new PathToUnindexedFieldType
                        {
                            FieldURI = UnindexedFieldURIType.folderDisplayName
                        },
                        FieldURIOrConstant = new FieldURIOrConstantType
                        {
                            Item = new ConstantValueType
                            {
                                Value = folderName
                            }
                        }
                    }
                }
            };
            FolderIdType localTargetFolderId = null;

            this.CallEwsWithRetries((LID)55484U, () => this.binding.FindFolder(findFolderType), delegate(ResponseMessageType responseMessage, int messageIndex)
            {
                FindFolderResponseMessageType findFolderResponseMessageType = responseMessage as FindFolderResponseMessageType;
                if (findFolderResponseMessageType != null && findFolderResponseMessageType.ResponseClass == ResponseClassType.Success && findFolderResponseMessageType.RootFolder != null && findFolderResponseMessageType.RootFolder.Folders != null && findFolderResponseMessageType.RootFolder.Folders.Length == 1)
                {
                    localTargetFolderId = findFolderResponseMessageType.RootFolder.Folders[0].FolderId;
                    if (this.IsTraceEnabled(TraceType.DebugTrace))
                    {
                        this.Tracer.TraceDebug <string, string>(0L, "Found the folder '{0}' with the id {1}", folderName, localTargetFolderId.Id);
                    }
                    return(true);
                }
                if (findFolderResponseMessageType != null && findFolderResponseMessageType.ResponseClass == ResponseClassType.Error && findFolderResponseMessageType.ResponseCode == ResponseCodeType.ErrorFolderNotFound)
                {
                    localTargetFolderId = null;
                    return(true);
                }
                return(false);
            }, null);
            folderId = localTargetFolderId;
            return(localTargetFolderId != null);
        }
        /// <summary>
        /// Search specific folders.
        /// </summary>
        /// <param name="findRequest">Specify a request for a FindFolder operation</param>
        /// <returns>A response to FindFolder operation request</returns>
        public FindFolderResponseType FindFolder(FindFolderType findRequest)
        {
            FindFolderResponseType findResponse = this.exchangeServiceBinding.FindFolder(findRequest);

            return(findResponse);
        }