1

我正在编写一个应用程序,该应用程序将使用 Outlook API 将日历项目从共享日历复制到我的个人日历。这是我到目前为止...

using Outlook = Microsoft.Office.Interop.Outlook;

public Outlook.Items GetPublicEntries(string calendar)
    {
        Microsoft.Office.Interop.Outlook.Items CalendarFolderItems = null;
        Outlook.Application oApp;
        oApp = new Outlook.Application();
        Outlook.NameSpace oNS = oApp.GetNamespace("MAPI");
        //oNS.Logon(Missing.Value, Missing.Value, true, true);

        Outlook.Recipient oRecip = (Outlook.Recipient)oNS.CreateRecipient(calendar);
        Outlook.MAPIFolder usersCalendarFolder = (Outlook.MAPIFolder)oNS.GetSharedDefaultFolder(oRecip, Outlook.OlDefaultFolders.olFolderCalendar);
        CalendarFolderItems = usersCalendarFolder.Items;
        return CalendarFolderItems;
    }



    static void Main(string[] args)
    {
        String[] Cals = { "Appointments","Deadlines","Hearings"};

        foreach (string cal in Cals)
        {
            CalendarItems calobj = new CalendarItems();
            Outlook.Items calobjs = calobj.GetPublicEntries(cal);

            foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in calobjs)
            {
                try
                {
                    Console.WriteLine(item.Subject + " -> " + item.Start.ToLongDateString() + " - " + item.GlobalAppointmentID);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            Console.ReadKey();
        }
    }

我可以从三个日历中返回项目列表,但现在我需要将它们复制到我的个人日历中,这就是我卡住的地方。有人知道该怎么做吗?

谢谢!

托尼

4

1 回答 1

0

Outlook 不会让您直接复制到指定的文件夹(与 AppointmentItem.Move() 不同,它将 MAPIFolder 对象作为参数) - 使用 AppointmentItem.Copy,然后是 AppointmentItem.Move:

AppointmentItem 复制项 = Item.Copy();
AppointmentItem newItem =copyedItem.Move(YourDestinationFolder);
newItem.Save();

请注意,当您调用 Copy() 时,Outlook 将清除全局约会 ID - 这意味着消息更新,即使它们直接进入您的收件箱,也不会找到约会。

如果使用 Redemption,则可以避免中间步骤 - 它的RDOAppointmentItem(派生自RDOMail对象)允许您在调用 CopyTo() 时传递目标文件夹。

于 2013-01-28T19:46:11.087 回答