0
votes

I am developing a web application in asp.net web forms framework. one of the requirement of application is to save records of future appointments of user. User also want to add this appointment to his outlook calendar. Now the problem is that my code is working locally. Appointments are being saved when I test application on my local machine. But when I deploy application on live server code give error and appointment do not saves in my outlook calendar. Kindly help me how to make it work on live server. Following is the code I'm using

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

I get the code from here. http://www.codeproject.com/Tips/384326/Add-to-Calender-Adding-event-to-Microsoft-Outlook

1
Welcome to Stack Overflow! It is a horrible idea to use Office Interop from ASP.NET or another server technology. These APIs were written for use in a desktop application, for automating Office (a suite of desktop applications). Server applications are different in many ways that make it a very, very bad idea to use Office Interop in them. It's also unsupported by Microsoft, and may violate your Office license. See Considerations for server-side Automation of OfficeJohn Saunders

1 Answers

0
votes

If you are going to use Outlook by Interop, then you would need to install it on your server. Without installed Outlook - it won't work.

PS. Your code will work only with Outlook account that is configured by default. And it will work only if you are using external service for appointments. Otherwise it will save that appointment just to Outlook on server, without updating it to your local Outlook

And using Interop in web applications on server side isn't a good idea, as it will starts new Outlook process every time, that is very resource expensive. Better way is to integrate with Calendar system that you are using, like Google Calendar, etc.