如何获取收件箱文件夹和项目计数?

发布于 2024-12-13 22:30:11 字数 1300 浏览 4 评论 0原文

我终于设法弄清楚如何创建收件箱、已发送项目、日历和邮件的项目计数。联系人,但我在文件夹计数方面遇到问题。

假设我在邮箱中创建了 5 个文件夹,每个文件夹中创建了 2 个子文件夹。当我运行此代码时,它会计算 5 个文件夹,而不是所有文件夹和子文件夹(相当于 15 个文件夹)。

我猜测是 foreach 语句或其他东西,但我仍然是新手:-)

#region Run Item Count

Microsoft.Office.Interop.Outlook.Application app = null;
Microsoft.Office.Interop.Outlook._NameSpace ns = null;

private void btnRunItemCount_Click(object sender, EventArgs e)
{
    app = new Microsoft.Office.Interop.Outlook.Application();
    ns = app.GetNamespace("MAPI");

    MAPIFolder oInbox = this.ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
    tbInboxItemCount.Text = oInbox.Items.Count.ToString();
    MAPIFolder oSentItems = this.ns.GetDefaultFolder(OlDefaultFolders.olFolderSentMail);
    tbSentMailItemCount.Text = oSentItems.Items.Count.ToString();
    MAPIFolder oCalendar = this.ns.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
    tbCalendarItemCount.Text = oCalendar.Items.Count.ToString();
    MAPIFolder oContacts = this.ns.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
    tbContactsItemCount.Text = oContacts.Items.Count.ToString();
    MAPIFolder oFolder = this.ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
    tbFolderItemCount.Text = oInbox.Folders.Count.ToString();
}

#endregion

感谢您收到的任何帮助!担

I finally managed to work out how to create item counts of the inbox, sent items, calendar & contacts but I'm having problems with the folder count.

Let say I have 5 folders created in my mailbox and 2 sub folders in each folder. When I run this code, it counts 5 folders instead of all folders and sub folders which would equal 15 folder.

I'm guessing a foreach statement or something but I still a newb :-)

#region Run Item Count

Microsoft.Office.Interop.Outlook.Application app = null;
Microsoft.Office.Interop.Outlook._NameSpace ns = null;

private void btnRunItemCount_Click(object sender, EventArgs e)
{
    app = new Microsoft.Office.Interop.Outlook.Application();
    ns = app.GetNamespace("MAPI");

    MAPIFolder oInbox = this.ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
    tbInboxItemCount.Text = oInbox.Items.Count.ToString();
    MAPIFolder oSentItems = this.ns.GetDefaultFolder(OlDefaultFolders.olFolderSentMail);
    tbSentMailItemCount.Text = oSentItems.Items.Count.ToString();
    MAPIFolder oCalendar = this.ns.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
    tbCalendarItemCount.Text = oCalendar.Items.Count.ToString();
    MAPIFolder oContacts = this.ns.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
    tbContactsItemCount.Text = oContacts.Items.Count.ToString();
    MAPIFolder oFolder = this.ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
    tbFolderItemCount.Text = oInbox.Folders.Count.ToString();
}

#endregion

Thanks for any help received! Dan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

━╋う一瞬間旳綻放 2024-12-20 22:30:11

您将需要递归处理以 Namespace.Folders 开头的所有文件夹。
我突然想到:

int allitems = CountFolders(ns.Folders);
...
private int CountFolders(文件夹文件夹)
{
    int c = 文件夹.count;
    foreach(文件夹中的MAPIFolder文件夹)
    {
     c += CountFolders(文件夹.文件夹);
    }
   返回c;
}

You will need to recursively process all folders starting with Namespace.Folders.
Off the top of my head:

int allitems = CountFolders(ns.Folders);
...
private int CountFolders(Folders folders)
{
   int c = folders.count;
   foreach (MAPIFolder folder in folders)
   {
     c += CountFolders(folder.Folders);
   }
   return c;
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文