【问题标题】:Copy Calendar Items from Shared Calendar to Personal Calendar with Outlook API使用 Outlook API 将日历项目从共享日历复制到个人日历
【发布时间】:2022-05-05 08:13:14
【问题描述】:

我正在编写一个应用程序,该应用程序将使用 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();
        }
    }

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

谢谢!

托尼

【问题讨论】:

    标签: c# calendar outlook


    【解决方案1】:

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

    AppointmentItem copiedItem = Item.Copy();
    AppointmentItem newItem = copiedItem.Move(YourDestinationFolder);
    newItem.Save();
    

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多