Outlook Interop: Password protected PST file headache
Posted
by Ed Manet
on Stack Overflow
See other posts from Stack Overflow
or by Ed Manet
Published on 2010-03-05T21:52:55Z
Indexed on
2010/04/30
5:07 UTC
Read the original article
Hit count: 260
Okay, I have no problem identifying the .PST file using the Outlook Interop assemblies in a C# app. But as soon as I hit a password protected file, I am prompted for a password. We are in the process of disabling the use of PSTs in our organization and one of the steps is to unload the PST files from the users' Outlook profile. I need to have this app run silently and not prompt the user. Any ideas? Is there a way to create the Outlook.Application object with no UI and then just try to catch an Exception on password protected files?
// create the app and namespace
Application olApp = new Application();
NameSpace olMAPI = olApp.GetNamespace("MAPI");
// get the storeID of the default inbox
string rootStoreID = olMAPI.GetDefaultFolder(OlDefaultFolders.olFolderInbox).StoreID;
// loop thru each of the folders
foreach (MAPIFolder fo in olMAPI.Folders)
{
// compare the first 75 chars of the storeid
// to prevent removing the Inbox folder.
string s1 = rootStoreID.Substring(1, 75);
string s2 = fo.StoreID.Substring(1, 75);
if (s1 != s2)
{
// unload the folder
olMAPI.RemoveStore(fo);
}
}
olApp.Quit();
© Stack Overflow or respective owner