如何通过Outlook VSTO插件列出共享Exchange邮箱中的收件箱文件夹中的子文件夹
我想在Outlook应用程序中创建VSTO插件
我尝试枚举共享交换邮箱中的子文件夹(这不是我的主邮箱,我只拥有该邮箱的完全访问权限)。
不幸的是,我的代码给了我空的收藏
I want to create VSTO addin to an Outlook Application
and I try to enumerate subfolders in shared exchange mailbox (this is not my primary mailbox, i have only full access rights to that mailbox).
Unfortunately, my code give me empty collection
using System;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace ManageSharedMailbox {
public partial class MSMAddIn {
private void ThisAddIn_Startup(object sender, System.EventArgs e){
PrepareRibbons();
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e){}
private void InternalStartup(){
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
private void PrepareRibbons() {
const string PomijanePrefixy = "!@#$%^&*()_+=[]{};':\",./<>?|\\`~ ";
const string PomijaneNazwy = "|archiwum|itemprocsearch|folder nadrzędny folderów osobistych|folder główny wyszukiwania|ipm_common_views|foldery wyszukiwania|freebusy data|";
foreach (Outlook.Folder folder in Application.Session.Folders) {
if (null == folder.Store) continue;
if (!folder.Store.IsOpen) continue;
Outlook.OlExchangeStoreType storetype = folder.Store.ExchangeStoreType;
if (storetype == Outlook.OlExchangeStoreType.olExchangePublicFolder) continue;
if (storetype != Outlook.OlExchangeStoreType.olExchangeMailbox) continue;
// I skip connected mailboxes without "SHARED" text in name
if (!folder.Name.ToLower().Contains("shared")) continue;
Outlook.MAPIFolder ofInbox = folder.Store.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
if (null == ofInbox) continue;
foreach (Outlook.Folder folderQuery in folder.Folders) {
if (folderQuery.DefaultItemType != Outlook.OlItemType.olMailItem) continue;
// I parse only INBOX folder
if (folderQuery.EntryID != ofInbox.EntryID) continue;
foreach (var item in folderQuery.Items) {
// Works, I can iterate through emails (not folders!) in this folder
}
foreach (Outlook.Folder folderEntries in folderQuery.Folders) {
// This collection is always empty,
// regardless of how many subfolders
// I have in the Inbox folder selected shared mailbox
// How to fill that collection ?
// or get list of these folders ?
}
break;
}
if (null != ofInbox) Marshal.ReleaseComObject(ofInbox);
}
}
}
}
如果我解析我的主要交易所或连接的.pst文件,这段代码可以正常工作。
我尝试过:
我尝试通过Outlook.Explored对象,但没有成功。
我还在HKEY_CURRENT_USER \Software \POLicies\Microsoft \Office\14.0\outlook \Cached Mode \ key
This code works ok, if I parse my primary exchange OR connected .pst files.
What I have tried:
I try to get via Outlook.Explored object, but without success.
I also changed "CacheOthersMail" value to 1 at HKEY_CURRENT_USER\Software\Policies\Microsoft\Office\14.0\outlook\Cached Mode\ key
中将CacheOthersMail值更改为1
%^& *()_ + = [] {};':\,。/<>?| \\`〜;
const string PomijaneNazwy = | archiwum | itemprocsearch |文件夹nadrzędnyfolderówosobistych|文件夹głównywyszukiwania| ipm_common_views | foldery wyszukiwania | freebusy data |;
foreach (Outlook.Folder文件夹在 Application.Session.Folders中){
if ( null == folder.Store)继续跨度>;
if (!folder.Store.IsOpen) continue ;
Outlook.OlExchangeStoreType storetype = folder.Store.ExchangeStoreType;
if (storetype == Outlook.OlExchangeStoreType.olExchangePublicFolder) continue ;
if (storetype!= Outlook.OlExchangeStoreType.olExchangeMailbox) continue ;
// 我跳过连接的邮箱,名称中没有共享文本
if (!folder.Name.ToLower()。Contains( shared)) continue ;
Outlook.MAPIFolder ofInbox = folder.Store.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
if ( null == ofInbox)继续跨度>;
foreach (Outlook.Folder folderQuery in folder.Folders){
if (folderQuery.DefaultItemType!= Outlook.OlItemType.olMailItem) continue ;
// 我只解析INBOX文件夹
if (folderQuery.EntryID!= ofInbox.EntryID) continue ;
foreach ( var item in folderQuery.Items){
// Works,我可以遍历电子邮件(不是文件夹) !)在此文件夹中
}
foreach (Outlook.Folder folderEntries in folderQuery.Folders){
// 此集合始终为空,
// 无论子文件夹有多少
// 我在收件箱文件夹中选择了共享邮箱
// 如何填写该集合?
// 或获取这些文件夹的列表?
}
break ;
}
if ( null != ofInbox)Marshal.ReleaseComObject(ofInbox) ;
}
}
}
}
%^&*()_+=[]{};':\",./<>?|\\`~ "; const string PomijaneNazwy = "|archiwum|itemprocsearch|folder nadrzędny folderów osobistych|folder główny wyszukiwania|ipm_common_views|foldery wyszukiwania|freebusy data|"; foreach (Outlook.Folder folder in Application.Session.Folders) { if (null == folder.Store) continue; if (!folder.Store.IsOpen) continue; Outlook.OlExchangeStoreType storetype = folder.Store.ExchangeStoreType; if (storetype == Outlook.OlExchangeStoreType.olExchangePublicFolder) continue; if (storetype != Outlook.OlExchangeStoreType.olExchangeMailbox) continue; // I skip connected mailboxes without "SHARED" text in name if (!folder.Name.ToLower().Contains("shared")) continue; Outlook.MAPIFolder ofInbox = folder.Store.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox); if (null == ofInbox) continue; foreach (Outlook.Folder folderQuery in folder.Folders) { if (folderQuery.DefaultItemType != Outlook.OlItemType.olMailItem) continue; // I parse only INBOX folder if (folderQuery.EntryID != ofInbox.EntryID) continue; foreach (var item in folderQuery.Items) { // Works, I can iterate through emails (not folders!) in this folder } foreach (Outlook.Folder folderEntries in folderQuery.Folders) { // This collection is always empty, // regardless of how many subfolders // I have in the Inbox folder selected shared mailbox // How to fill that collection ? // or get list of these folders ? } break; } if (null != ofInbox) Marshal.ReleaseComObject(ofInbox); } } } }
如果我解析我的主要交易所或连接的.pst文件,这段代码可以正常工作。
我尝试过:
我尝试通过Outlook.Explored对象,但没有成功。
我还在HKEY_CURRENT_USER \Software \POLicies \ Mysoftoft \Office\14.0 \outlook \Cached Mode \ key
This code works ok, if I parse my primary exchange OR connected .pst files.
What I have tried:
I try to get via Outlook.Explored object, but without success.
I also changed "CacheOthersMail" value to 1 at HKEY_CURRENT_USER\Software\Policies\Microsoft\Office\14.0\outlook\Cached Mode\ key