从outlook获取按大小排序的文件夹
本文关键字:排序 文件夹 outlook 获取 | 更新日期: 2023-09-27 17:59:23
我使用以下代码从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);
}
否,Outlook中的Folders
集合不可排序。
即使您使用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