0

我想显示共享日历。我在网上搜索,我找到了这段代码:

 static void Main(string[] args)
    {

        Outlook.Application objOLApp;
        Outlook.MAPIFolder objFolder;
        Outlook.Explorer objExplorer;
        Outlook.MAPIFolder objSubFolder;
        Outlook.AppointmentItem objCalenderItem;
        Outlook.Folders objOutlookFolders;
        int intFolderCtr;
        int intSubFolderCtr;
        int intAppointmentCtr;
        // >> Initialize The Base Objects
        objOLApp = new Outlook.Application();
        objOutlookFolders = objOLApp.Session.Folders;
        // >> Loop Through The PST Files Added n Outlook
        for (intFolderCtr = 1; intFolderCtr <= objOutlookFolders.Count; intFolderCtr++)
        {
            objFolder = objOutlookFolders[intFolderCtr];
            objExplorer = objFolder.GetExplorer();
            // >> Loop Through The Folders In The PST File
            for (intSubFolderCtr = 1; intSubFolderCtr <= objExplorer.CurrentFolder.Folders.Count; intSubFolderCtr++)
            {
                objSubFolder = objExplorer.CurrentFolder.Folders[intSubFolderCtr];
                // >> Check if Folder Contains Appointment Items
                if (objSubFolder.DefaultItemType == Outlook.OlItemType.olAppointmentItem)
                {
                    // >> Loop Through Appointment Items
                    for (intAppointmentCtr = 1; intAppointmentCtr <= objSubFolder.Items.Count; intAppointmentCtr++)
                    {
                        // >> Get Teh Calender Item From The Calender Folder
                        objCalenderItem = objSubFolder.Items[intAppointmentCtr];
                        // >> Process Appointment Item Accordingly
                        Console.WriteLine(objCalenderItem.Subject);
                        Console.WriteLine(objCalenderItem.Location + "," + objCalenderItem.Start.ToLongDateString());
                        Console.WriteLine();
                        Console.WriteLine();
                    }
                }
            }
        }
        // >> Close Application
       // objOLApp.Quit();
        // >> Release COM Object
        System.Runtime.InteropServices.Marshal.ReleaseComObject(objOLApp);
        objOLApp = null;
        Console.ReadLine();
    }

但它只看到我的约会。

我想查看所有共享日历。因为我安排了会议,但我不知道其他人的忙碌或空闲。那么如何显示其他人的日历?

编辑:

我改变了这条线

objOutlookFolders = objOLApp.Session.Folders;

objOutlookFolders = oNs.GetSharedDefaultFolder(oRep, OlDefaultFolders.olFolderCalendar).Folders;

我加了这个

 NameSpace oNs = objOLApp.GetNamespace("MAPI");
 Recipient oRep = oNs.CreateRecipient(objOLApp.Session.CurrentUser.Name);

但我仍然得到错误。

新版本是

        static void Main(string[] args)
        {

            Outlook.Application objOLApp;
            Outlook.MAPIFolder objFolder;
            Outlook.Explorer objExplorer;
            Outlook.MAPIFolder objSubFolder;
            Outlook.AppointmentItem objCalenderItem;
            Outlook.Folders objOutlookFolders;
            int intFolderCtr;
        int intSubFolderCtr;
        int intAppointmentCtr;
        // >> Initialize The Base Objects
        objOLApp = new Outlook.Application();



        NameSpace oNs = objOLApp.GetNamespace("MAPI");
        Recipient oRep = oNs.CreateRecipient(objOLApp.Session.CurrentUser.Name);


        oRep.Resolve();
        //if (oRep.Resolved)
            objOutlookFolders = oNs.GetSharedDefaultFolder(oRep, OlDefaultFolders.olFolderCalendar).Folders;

        //else
        //    objOutlookFolders = objOLApp.Session.Folders;


        // >> Loop Through The PST Files Added n Outlook
        for (intFolderCtr = 1; intFolderCtr <= objOutlookFolders.Count; intFolderCtr++)
        {
            objFolder = objOutlookFolders[intFolderCtr];
            objExplorer = objFolder.GetExplorer();
            // >> Loop Through The Folders In The PST File
            for (intSubFolderCtr = 1; intSubFolderCtr <= objExplorer.CurrentFolder.Folders.Count; intSubFolderCtr++)
            {
                objSubFolder = objExplorer.CurrentFolder.Folders[intSubFolderCtr]; 
                // >> Check if Folder Contains Appointment Items
                if (objSubFolder.DefaultItemType == Outlook.OlItemType.olAppointmentItem)
                {
                    // >> Loop Through Appointment Items
                    for (intAppointmentCtr = 1; intAppointmentCtr <= objSubFolder.Items.Count; intAppointmentCtr++)
                    {
                        // >> Get Teh Calender Item From The Calender Folder
                        objCalenderItem = objSubFolder.Items[intAppointmentCtr];
                        // >> Process Appointment Item Accordingly
                        Console.WriteLine(objCalenderItem.Subject);
                        Console.WriteLine(objCalenderItem.Location + "," + objCalenderItem.Start.ToLongDateString());
                        Console.WriteLine();
                        Console.WriteLine();
                    }
                }
            }
        }
        // >> Close Application
        // objOLApp.Quit();
        // >> Release COM Object
        System.Runtime.InteropServices.Marshal.ReleaseComObject(objOLApp);
        objOLApp = null;
        Console.ReadLine();

    }

请帮帮我..我还在工作。但它没有。

4

1 回答 1

0

使用 Namespace.GetSharedDefaultFolder 打开其他用户的默认日历文件夹。

于 2013-07-31T16:44:51.287 回答