c#,Microsoft.Office.Interop.Outlook,非默认文件夹

时间:2016-04-17 11:33:22

标签: c# outlook

我需要对非默认日历进行计数,查看,编辑项目,但我无法访问它。

如何在c#中访问非默认日历(对于拥有Outlook.MAPIFolder)?请

在“\ xxx@outlook.fr”中创建新的“Adhésion”日历后。我想在c#app中访问它。

这是正确的方法吗?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Outlook = Microsoft.Office.Interop.Outlook;

namespace ACC_adhérents
{
    class Program
    {
        static void Main(string[] args)
        {
            Outlook.Application app = new Outlook.Application();

            Outlook.NameSpace ns = app.GetNamespace("mapi");

            ns.Logon("xxxx@outlook.fr", Missing.Value, true, true);

            Outlook.MAPIFolder inboxFolder = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
            Outlook.MAPIFolder parentFolder = inboxFolder.Parent;
            Outlook.MAPIFolder adhesionFolder = parentFolder.Folders["Tâches - Adhésion"];

            Console.WriteLine("Folder Name: {0}, EntryId: {1}", adhesionFolder.Name, adhesionFolder.EntryID);
            Console.WriteLine("Num Items: {0}", adhesionFolder.Items.Count.ToString());

            ns.Logoff();
        }
    }
}

1 个答案:

答案 0 :(得分:0)

如果文件夹已在Outlook中打开,请从ns.Folders集合开始(返回配置文件中所有商店的顶级文件夹)并深入查看所需的文件夹。您还可以使用Namespace.Stores集合到达所需的辅助存储,然后使用Store.GetDefaultFolder(对于默认文件夹)或Store.GetRootFolder与商店的顶级fodler一起使用strat。