Reputation: 553
I managed to get the full name of a folder using this code copied from here:
private static string GetFullFolderName(Microsoft.Exchange.WebServices.Data.ExchangeService EServ, string FolderID)
{
Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition folderPathExtendedProp = new Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(26293, Microsoft.Exchange.WebServices.Data.MapiPropertyType.String);
Microsoft.Exchange.WebServices.Data.PropertySet folderPropSet = new Microsoft.Exchange.WebServices.Data.PropertySet(Microsoft.Exchange.WebServices.Data.BasePropertySet.FirstClassProperties) { folderPathExtendedProp };
Microsoft.Exchange.WebServices.Data.Folder folder = Microsoft.Exchange.WebServices.Data.Folder.Bind(EServ, FolderID, folderPropSet);
string path = null;
folder.TryGetProperty(folderPathExtendedProp, out path);
return path?.Replace("\ufffe", "\\");
}
Now, I'd like to search folders by its full name. I wrote a function, but this seems just to look for the DisplayName.
public static Microsoft.Exchange.WebServices.Data.FindFoldersResults GetFolders(Microsoft.Exchange.WebServices.Data.ExchangeService EServ, string NamePart = "")
{
if (NamePart.Trim().Length > 0) {
Microsoft.Exchange.WebServices.Data.SearchFilter.ContainsSubstring SF = new Microsoft.Exchange.WebServices.Data.SearchFilter.ContainsSubstring(Microsoft.Exchange.WebServices.Data.FolderSchema.DisplayName, NamePart);
return EServ.FindFolders(Microsoft.Exchange.WebServices.Data.WellKnownFolderName.Root, SF, new Microsoft.Exchange.WebServices.Data.FolderView(System.Int32.MaxValue) { Traversal = Microsoft.Exchange.WebServices.Data.FolderTraversal.Deep });
}else{
return EServ.FindFolders(Microsoft.Exchange.WebServices.Data.WellKnownFolderName.Root, new Microsoft.Exchange.WebServices.Data.FolderView(System.Int32.MaxValue) { Traversal = Microsoft.Exchange.WebServices.Data.FolderTraversal.Deep });
}
}
Is there a possibility to use the full name of the folder as search criteria instead of the DisplayName?
Thank you and regards, Jan
Upvotes: 0
Views: 1370
Reputation: 22032
No you can't create a restriction on that property because it a calculated property. I would suggest you start your Search at
WellKnownFolderName.MsgFolderRoot
Root is going to include all the Non_IPM_Subtree folder which aren't visible to user so it just makes your query less efficient.
If you add that property to the PropertySet of the folderView you can then just filter the results that come back to match the path your searching for. Using a IsEqual SearchFilter and just the exact Folder DisplayName is also going to speed your search up as well. You should just then be able to get rid of any extract folder name (eg same name different path) when you filter the result set based on the path your looking for.
Personally when i need to do this I split the path out and do shallow traversals from the parent folder. Its more requests but I've never had any problems with reliability and speed of that method and it also works for Public folders where the above method would fail eg Exchange Web Service FolderId for a folder created by user.
Upvotes: 1