使用asp.net添加到outlook的约会

时间:2013-12-26 11:11:03

标签: asp.net outlook office-interop

我正在asp.net web forms框架中开发一个web应用程序。应用程序的要求之一是保存用户未来约会的记录。用户还希望将此约会添加到他的Outlook日历中。现在问题是我的代码在本地工作。当我在本地计算机上测试应用程序时,正在保存约会。但是当我在实时服务器代码上部署应用程序时,会出现错误并且约会不会保存在我的Outlook日历中。请帮助我如何使其在实时服务器上工作。以下是我正在使用的代码

Private Sub AddToCalander()

        Try

        Dim olApp As Microsoft.Office.Interop.Outlook._Application = DirectCast(New Microsoft.Office.Interop.Outlook.Application(), Microsoft.Office.Interop.Outlook._Application)
        Dim mapiNS As Microsoft.Office.Interop.Outlook.NameSpace = olApp.GetNamespace("MAPI")

        Dim profile As String = ""
            mapiNS.Logon(profile, Nothing, Nothing, Nothing)
        Dim apt As Microsoft.Office.Interop.Outlook._AppointmentItem = DirectCast(olApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem), Microsoft.Office.Interop.Outlook._AppointmentItem)

        apt.Subject = ddItineraryItems.SelectedItem.Text
            apt.Body = txtPItinerary_Desc.Text

            apt.Start = CDate(txtDateFromPopup.Text)
            apt.End = CDate(txtDateToPopup.Text)

        apt.BusyStatus = Microsoft.Office.Interop.Outlook.OlBusyStatus.olTentative
        apt.AllDayEvent = False
        apt.Location = dcmbDealer.SelectedItem.Text & "," & dcmbShowroom.SelectedItem.Text

        apt.Save()

        Catch ex As Exception
            AlertMessage.showError("Unable to add itinerary detail to outlook calendar")
            Exit Sub
        End Try 
     End Sub

我从这里得到代码。 http://www.codeproject.com/Tips/384326/Add-to-Calender-Adding-event-to-Microsoft-Outlook

1 个答案:

答案 0 :(得分:0)

如果您打算使用Outlook by Interop,那么您需要在服务器上安装它。没有安装Outlook - 它将无法正常工作。

PS。您的代码仅适用于默认配置的Outlook帐户。只有当您使用外部服务进行约会时,它才会起作用。否则,它会将该约会仅保存到服务器上的Outlook,而不将其更新到本地Outlook

在服务器端的Web应用程序中使用Interop并不是一个好主意,因为它每次都会启动新的Outlook进程,这非常耗费资源。更好的方法是与您正在使用的日历系统集成,如Google日历等。

相关问题