In .NET (C#, etc) you can use the Exchange WebServices APIs to get access to the public folders by adding the NuGet package Microsoft Exchange WebServices
to your application.
You'll need an instance of Microsoft.Exchange.WebServices.Data.ExchangeService
to work with, plus a valid login for the server - passed in as a System.Net.NetworkCredential
. For instance:
ExchangeService service = new ExchangeService();
service.AutodiscoverUrl("myemail@mycompany.com");
service.Credentials = new NetworkCredential("myemail", "mypassword", "MYDOMAIN");
Once you have that, public folders can be searched for using something like this:
public Folder GetFolder(string path)
{
FolderView fview = new FolderView(100);
fview.PropertySet = new PropertySet(BasePropertySet.IdOnly);
fview.PropertySet.Add(FolderSchema.DisplayName);
fview.Traversal = FolderTraversal.Shallow;
SearchFilter filter = new SearchFilter.ContainsSubstring(FolderSchema.DisplayName, path);
var fldrs = exchange.FindFolders(WellKnownFolderName.PublicFoldersRoot, filter, fview);
if (fldrs != null)
return fldrs.FirstOrDefault();
}
That will return a folder in the root of your Public Folder tree by name. If you want to go deeper you can walk the tree using this method:
public Folder GetFolder(Folder src, string FolderName)
{
FolderView fview = new FolderView(100);
fview.PropertySet = new PropertySet(BasePropertySet.IdOnly);
fview.PropertySet.Add(FolderSchema.DisplayName);
fview.Traversal = FolderTraversal.Shallow;
SearchFilter filter = new SearchFilter.ContainsSubstring(FolderSchema.DisplayName, FolderName);
var fldrs = src.FindFolders(filter, fview);
if (fldrs == null)
return null;
return fldrs.FirstOrDefault();
}
You can monkey with the Traversal
option and the SearchFilter
to get the Exchange WebServices to do some of the work for you. My public folders are stored on a server in another country (not by my choice) so it was faster to do it this way. YMMV.
For all of the above you'll need to include the following:
using System.Net;
using Microsoft.Exchange.WebServices.Data;