public static FolderId FindFolder(Microsoft.Exchange.WebServices.Data.ExchangeService service) { var resultid = new FolderId("0"); var responseview = new FolderView(1); var filter = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, "sync-adressen"); var folderresponse = service.FindFolders(WellKnownFolderName.PublicFoldersRoot, filter, responseview); if (folderresponse.Count() == 1) { var responseview2 = new FolderView(1); var filter2 = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, "sync-contacten"); var folderresponse2 = service.FindFolders(folderresponse.First().Id, filter2, responseview2); if (folderresponse2.Count() == 1) { var responseview3 = new FolderView(1); var filter3 = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, "syncContacts"); var folderresponse3 = service.FindFolders(folderresponse2.First().Id, filter3, responseview3); if (folderresponse3.Count() == 1) { resultid = folderresponse3.First().Id; } } } return(resultid); }
private static void GetAllFolders(Exchange.ExchangeService Service, string LogFilePath) { Exchange.ExtendedPropertyDefinition oIsHidden = default(Exchange.ExtendedPropertyDefinition); List <Exchange.Folder> oFolders = default(List <Exchange.Folder>); Exchange.FindFoldersResults oResults = default(Exchange.FindFoldersResults); bool lHasMore = false; Exchange.Folder oChild = default(Exchange.Folder); Exchange.FolderView oView = default(Exchange.FolderView); short nPageSize = 0; short nOffSet = 0; List <string> oPaths = default(List <string>); List <string> oPath = default(List <string>); oIsHidden = new Exchange.ExtendedPropertyDefinition(0x10f4, Exchange.MapiPropertyType.Boolean); nPageSize = 1000; oFolders = new List <Exchange.Folder>(); lHasMore = true; nOffSet = 0; while (lHasMore) { oView = new Exchange.FolderView(nPageSize, nOffSet, Exchange.OffsetBasePoint.Beginning); oView.PropertySet = new Exchange.PropertySet(Exchange.BasePropertySet.IdOnly); oView.PropertySet.Add(oIsHidden); oView.PropertySet.Add(Exchange.FolderSchema.ParentFolderId); oView.PropertySet.Add(Exchange.FolderSchema.DisplayName); oView.PropertySet.Add(Exchange.FolderSchema.FolderClass); oView.PropertySet.Add(Exchange.FolderSchema.TotalCount); oView.Traversal = Exchange.FolderTraversal.Deep; oResults = Service.FindFolders(Exchange.WellKnownFolderName.MsgFolderRoot, oView); oFolders.AddRange(oResults.Folders); lHasMore = oResults.MoreAvailable; if (lHasMore) { nOffSet += nPageSize; } } oFolders.RemoveAll(Folder => Folder.ExtendedProperties(0).Value == true); oFolders.RemoveAll(Folder => Folder.FolderClass != "IPF.Note"); oPaths = new List <string>(); oFolders.ForEach(Folder => { oChild = Folder; oPath = new List <string>(); do { oPath.Add(oChild.DisplayName); oChild = oFolders.SingleOrDefault(Parent => Parent.Id.UniqueId == oChild.ParentFolderId.UniqueId); } while (oChild != null); oPath.Reverse(); oPaths.Add("{0}{1}{2}".ToFormat(Strings.Join(oPath.ToArray, DELIMITER), Constants.vbTab, Folder.TotalCount)); }); oPaths.RemoveAll(Path => Path.StartsWith("Sync Issues")); File.WriteAllText(LogFilePath, Strings.Join(oPaths.ToArray, Constants.vbCrLf)); }
/// <summary> /// Tests <see cref="Exchange.ExchangeService"/> connection. /// </summary> /// <param name="service"><see cref="Exchange.ExchangeService"/> instance.</param> /// <param name="userConnection"><see cref="UserConnection"/> instance.</param> /// <param name="senderEmailAddress">Sender email address.</param> /// <param name="stopOnFirstError">Stop synchronization triggers on first error flag.</param> public static void TestConnection(this Exchange.ExchangeService service, UserConnection userConnection = null, string senderEmailAddress = "", bool stopOnFirstError = false) { SynchronizationErrorHelper helper = SynchronizationErrorHelper.GetInstance(userConnection); try { service.FindFolders(Exchange.WellKnownFolderName.MsgFolderRoot, new Exchange.FolderView(1)); helper.CleanUpSynchronizationError(senderEmailAddress); } catch (Exception ex) { helper.ProcessSynchronizationError(senderEmailAddress, ex, stopOnFirstError); throw; } }
/// <summary> /// Returns Id of first child folder by name and root folder id. /// If the value can not be obtained, the method returns <c>null</c>.</summary> /// <param name="exchangeService">Exchange service.</param> /// <param name="parentId">Root folder Id.</param> /// <param name="childName">Display name of the finding folder.</param> /// <returns>Id of child folder, or <c>null</c>.</returns> private Exchange.FolderId GetChildIdByName(Exchange.ExchangeService exchangeService, Exchange.FolderId parentId, string childName) { Exchange.SearchFilter filter = new Exchange.SearchFilter .IsEqualTo(Exchange.FolderSchema.DisplayName, childName); var result = exchangeService.FindFolders(parentId, filter, new Exchange.FolderView(1)); if (!result.Folders.Any()) { return(null); } return(result.Folders[0].Id); }