Silenty将约会添加到日历

时间:2014-10-27 08:40:44

标签: c# asp.net calendar outlook

我有一个本地网页,域用户通过该页面添加约会(输入主题,正文,开始结束日期等详细信息)并保存到数据库。

我想在默认情况下同时将约会添加到客户端的Outlook日历中(不提示ics文件保存/打开)。

我使用以下函数添加到日历中,并使用新生成的GUID:

 protected void sendToOutlook(Guid outlook_ID)
    {

        _Application olApp = (_Application)new Application();
        NameSpace mapiNS = olApp.GetNamespace("MAPI");

        string profile = email;
        mapiNS.Logon(profile, null, null, null);

        _AppointmentItem apt = (_AppointmentItem)
                olApp.CreateItem(OlItemType.olAppointmentItem);

        // set some properties
        apt.Subject = txtSubject.Text;
        apt.Body = txtDetail.Text;

        apt.Start = Convert.ToDateTime(txtStart.Text + " " + ddStartHour.SelectedValue);// new DateTime(2014, 10, 21, 14, 00, 00);
        apt.End = Convert.ToDateTime(txtEnd.Text + " " + ddEndHour.SelectedValue);
        DateTime dt = new DateTime(2014, 10, 21, 14, 00, 00);
        apt.ReminderMinutesBeforeStart = 15;           // Number of minutes before the event for the remider
        apt.BusyStatus = OlBusyStatus.olTentative;    // Makes it appear bold in the calendar

        apt.AllDayEvent = false;

        apt.Location = txtLocation.Text;               

        apt.RequiredAttendees = email + ";" + txtAttendee.Text;

        apt.UserProperties.Add("UID", OlUserPropertyType.olText);

        apt.UserProperties["UID"].Value = outlook_ID.ToString();

        apt.Close(OlInspectorClose.olSave);

    }

这适用于本地完美但不在服务器端工作。没有错误或警告,根本没有回应。谁能告诉我为什么?

1 个答案:

答案 0 :(得分:1)

您不应该在ASP.NET服务器进程中使用Office互操作。 Microsoft strongly dis-recommends it,特别是出于这个原因:意外行为:

  

Microsoft目前不建议也不支持任何无人参与的非交互式客户端应用程序或组件(包括ASP, ASP.NET ,DCOM和NT服务)的Microsoft Office应用程序自动化),因为Office在此环境中运行时Office可能会出现不稳定的行为和/或死锁

如果您使用的是任何现代版本的Exchange,请使用Exchange web service,这非常易于使用。我不熟悉其他平台及其SDK。

另一个问题可能是您没有在用户的日历中写入,而是在负责运行Web服务器的用户帐户之一。

相关问题