好的,我在 C# 应用程序中使用 Outlook 互操作程序集识别 .PST 文件没有问题。但是,一旦我点击了受密码保护的文件,系统就会提示我输入密码。我们正在我们的组织中禁用 PST 的使用,其中一个步骤是从用户的 Outlook 配置文件中卸载 PST 文件。我需要让这个应用程序静默运行而不提示用户。有任何想法吗?有没有办法在没有 UI 的情况下创建 Outlook.Application 对象,然后尝试在受密码保护的文件上捕获异常?
// 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();