0

我使用以下代码从 Outlook 检索所有文件夹:

 public void getFolderPath()
    {
        try
        {
            OutLook.Application oApp = new OutLook.Application();
            OutLook.NameSpace oNS = (OutLook.NameSpace)oApp.GetNamespace("MAPI");
            oNS.Logon(Missing.Value, Missing.Value, false, true);

            foreach (MAPIFolder folder in oNS.Folders)
            {
                GetFolders(folder);
            }

            Marshal.ReleaseComObject(oApp);


        }
        catch (System.Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }

这显示了 OutLook 中列出的从上到下的所有文件夹,有没有一种方法可以显示它们或通过它们按大小升序排列。

类似于:

foreach (MAPIFolder folder in oNS.Folders.sortbysize())
        {
            GetFolders(folder);
        }
4

1 回答 1

0

不,Outlook 中的文件夹集合不可排序。
即使您要使用 Extended MAPi(仅限 C++ 或 Delphi)或Redemption(任何语言),在 PR_MESSAGE_SIZE 属性上排序文件夹也不起作用:PST 提供程序不会公开它,并且 Exchange 倾向于为所有文件夹返回 0。
您可以按 PR_CONTENT_COUNT 属性(文件夹中的邮件数)排序,但不能按大小排序。以下脚本 (Outlook VBA) 使用Redemption按 PR_CONTENT_COUNT 对文件夹进行排序:

set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT 
set Folders = Session.Stores.DefaultStore.IPMRootFolder.Folders
Folders.MAPITable.Sort "http://schemas.microsoft.com/mapi/proptag/0x36020003", true
for each Folder in Folders
  Debug.print Folder.Name & " (" & Folder.Fields("http://schemas.microsoft.com/mapi/proptag/0x36020003") & ")"
next 

一个更快的版本(它不打开子文件夹并使用 ExecSQL 方法)将是

set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT 
set Folders = Session.Stores.DefaultStore.IPMRootFolder.Folders
set MAPITable = Folders.MAPITable
MAPITable.Sort "http://schemas.microsoft.com/mapi/proptag/0x36020003", true
set Recordset = MAPITable.ExecSQL("SELECT ""http://schemas.microsoft.com/mapi/proptag/0x3001001E"" AS PR_DISPLAY_NAME, " & _
                                  " ""http://schemas.microsoft.com/mapi/proptag/0x36020003"" AS PR_CONTENT_COUNT " & _
                                  " from Table")
while not Recordset.EOF
    Debug.Print Recordset.Fields("PR_DISPLAY_NAME").Value & " (" & Recordset.Fields("PR_CONTENT_COUNT").Value & ")"
    Recordset.MoveNext
wend
于 2013-02-14T16:39:49.970 回答