MAPI 查找联系人和日历文件夹

发布于 2024-09-02 16:46:01 字数 1519 浏览 5 评论 0 原文

在我的 Outlook 中,我有 1 个交换连接和 2 个个人文件夹。

我想从日历和联系人中获取所有项目,所以我使用:

           /**
             * Create outlook application
             */
            Outlook.Application oApp = new Outlook.Application();
            Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
            oNS.Logon(Missing.Value, Missing.Value, true, true);

            /**
             * Loop through all the folders
             */
            foreach (Outlook.MAPIFolder oFolder in oNS.Folders)
            {
                if (oFolder.Name == "Public Folders")
                {
                    break;
                }

                /**
                 * Get calendar items
                 */
                //Outlook.MAPIFolder oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
                Outlook.MAPIFolder oCalendar = oFolder.Folders[5];
                Outlook.Items oCalendarItems = oCalendar.Items;

                //Outlook.MAPIFolder oContacts = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
                Outlook.MAPIFolder oContacts = oFolder.Folders[7];
                Outlook.Items oContactItems = oContacts.Items;

但这不起作用 oFolder.Folders[5] 对于日历来说并不总是 5,有时它是一个不同的值。

我无法按名称找到商品 oFolder.Folders["日历"]; 因为在荷兰语中该文件夹将被命名为“Agenda”。

通常我使用: Outlook.MAPIFolder oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);

但随后我只获得默认日历。我怎样才能获得其他日历?

In my outlook I have 1 exchange connection and 2 Personal Folders.

I want to go fetch ALL items from the calendars and contacts so I use:

           /**
             * Create outlook application
             */
            Outlook.Application oApp = new Outlook.Application();
            Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
            oNS.Logon(Missing.Value, Missing.Value, true, true);

            /**
             * Loop through all the folders
             */
            foreach (Outlook.MAPIFolder oFolder in oNS.Folders)
            {
                if (oFolder.Name == "Public Folders")
                {
                    break;
                }

                /**
                 * Get calendar items
                 */
                //Outlook.MAPIFolder oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
                Outlook.MAPIFolder oCalendar = oFolder.Folders[5];
                Outlook.Items oCalendarItems = oCalendar.Items;

                //Outlook.MAPIFolder oContacts = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
                Outlook.MAPIFolder oContacts = oFolder.Folders[7];
                Outlook.Items oContactItems = oContacts.Items;

But this does not work
oFolder.Folders[5]
is not always 5 for the calendar, sometimes it's a different value.

I cannot find the items by name
oFolder.Folders["Calendar"];
because in Dutch the folder will be named "Agenda".

Usually I use:
Outlook.MAPIFolder oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);

But then I only get the default calendar. How can I get the other calendars?

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

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

发布评论

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

评论(1

千里故人稀 2024-09-09 16:46:06

我认为您必须浏览文件夹列表并查看 Folder.DefaultItemType 属性 返回 OlItemType 类型,您希望返回 olAppointmentItem & ol联系项目

Marcus

I think you would have to roll through youe list of folders and look at the Folder.DefaultItemType Property which returns a OlItemType type you would want the ones that return olAppointmentItem & olContactItem

Marcus

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