I tried to read emails from an email Outlook account in a .pst/.ost file. The code is as follows.
Outlook.Application myApp = new Outlook.Application();
Outlook.NameSpace mapiNameSpace = myApp.GetNamespace("MAPI");
// Get the email account root folder
Outlook.MAPIFolder myEmail = mapiNameSpace.Folders[textBox_EmailBody_Account.Text.Trim()];
// Get the specific subfolder
Outlook.MAPIFolder emailFolder = (Outlook.MAPIFolder)myEmail.Folders[textBox_EmailBody_Folder.Text.Trim()];
It works fine for a .pst file, but fails for a .ost file (myEmail == null). The .pst file is in the folder "C:\Users\name\Documents\Outlook Files" and the .ost file is in "C:\Users\name\AppData\Local\Microsoft\Outlook". I need help on this. Thanks.
I tried to read emails from an email Outlook account in a .pst/.ost file. The code is as follows.
Outlook.Application myApp = new Outlook.Application();
Outlook.NameSpace mapiNameSpace = myApp.GetNamespace("MAPI");
// Get the email account root folder
Outlook.MAPIFolder myEmail = mapiNameSpace.Folders[textBox_EmailBody_Account.Text.Trim()];
// Get the specific subfolder
Outlook.MAPIFolder emailFolder = (Outlook.MAPIFolder)myEmail.Folders[textBox_EmailBody_Folder.Text.Trim()];
It works fine for a .pst file, but fails for a .ost file (myEmail == null). The .pst file is in the folder "C:\Users\name\Documents\Outlook Files" and the .ost file is in "C:\Users\name\AppData\Local\Microsoft\Outlook". I need help on this. Thanks.
Share Improve this question asked 20 hours ago E ZhangE Zhang 1717 bronze badges1 Answer
Reset to default 0It means the top folder name does not match what you pass to mapiNameSpace.Folders[]
. Look at the value of textBox_EmailBody_Account.Text
and compare it to the folders names in the mapiNameSpace.Folders
collection.