简体   繁体   中英

c#, Microsoft.Office.Interop.Outlook, non default-folder

I need a count, view, edit items of a non-default calendar, but I have a problem to access to it.

How to access to a non-default calendar in c# (for have a Outlook.MAPIFolder) ? please

After create the new "Adhésion" calendar in "\\xxx@outlook.fr". I would like to access to it in c# app.

Is it a correct way ?

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();
        }
    }
}

If the folder is already opened in Outlook, start with the ns.Folders collection (returns top level folders of all stores in the profile) and drill down to the folder you want. You can also use the Namespace.Stores collection to get to the secondary store you want and then use Store.GetDefaultFolder (for the default folders) or Store.GetRootFolder to strat with the top fodler of the store.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM