Microsoft Outlook 14.0 개체 라이브러리 참조 및 아래 코드를 사용하여 모든 하위 폴더를 포함하여 사서함 아래에 나열된 모든 폴더 수를 계산하고 싶지만 문제가 있습니다.Outlook 사서함의 하위 폴더는 어떻게 계산합니까?
는이 코드는 최상위 폴더와 두 번째 수준 폴더를 계산하지만, 아래에 하위 폴더를 계산하지 않습니다. foreach 문 내에서 countRootFolders 메서드의 문제가 있지만 작동하지 않습니다. 누구든지 도와 줄 수 있습니까?
Microsoft.Office.Interop.Outlook.Application app = null;
Microsoft.Office.Interop.Outlook._NameSpace ns = null;
private void button1_Click(object sender, EventArgs e)
{
app = new Microsoft.Office.Interop.Outlook.Application();
ns = app.GetNamespace("MAPI");
MessageBox.Show(countRootFolders().ToString());
}
public int countRootFolders()
{
Microsoft.Office.Interop.Outlook.MAPIFolder rootFolder = this.ns.Session.DefaultStore.GetRootFolder();
int rootCount = rootFolder.Folders.Count;
foreach (Microsoft.Office.Interop.Outlook.MAPIFolder subfolder in rootFolder.Folders)
{
rootCount += subfolder.Folders.Count;
}
return rootCount;
}
어떤 도움도 크게 appreicated !!
재귀를 이해하려면 먼저 재귀를 이해해야합니다. – zeroef
새 코드 ... MessageBox.Show (countRootFolders (rootFolder) .ToString()); public int countRootFolders (Microsoft.Office.Interop.Outlook.MAPIFolder aFolder) { int rootCount = aFolder.Folders.Count; foreach (aFolder.Folders의 Microsoft.Office.Interop.Outlook.MAPIFolder 하위 폴더) { rootCount + = countRootFolders (하위 폴더); } return rootCount; } –