I’m trying to use the Backup() method of the IEWSClient interface, however I keep running into null reference exceptions. The code from my test application is pretty simple:
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "firstname.lastname@example.org", "password", "domain.com"); ExchangeFolderInfoCollection col = client.ListSubFolders(client.MailboxInfo.RootUri); client.Backup(client.ListSubFolders(client.MailboxInfo.RootUri), @"d:\dev\test.pst", BackupOptions.Recursive); // System.NullReferenceException: 'Object reference not set to an instance of an object.'
The last line always throws a null reference exception, though I can’t see why. All the objects have values, and a PST file (though 256KB and empty) is created before the exception is thrown.
Am I doing something wrong in the creation of the IEWSClient object?
If it helps, my goal is to create an application that can be given to some of our users so that they can export their mailboxes from Exchange Online to PST files without having to use Outlook. If there is a better way to accomplish this, can someone point me in the right direction?
I appreciate any assistance you can give.