Add event to outlook calender in VB.NET

Posted on 2013-09-20
Medium Priority
Last Modified: 2013-11-12
I am using the following code to add an event to Outlook calendar. I have added the reference to Outlook (Microsoft Outlook 12.0 Object Library). I went to the security tab in the properties of the folder C:\Program Files\Microsoft Office\Office12 and added permission for ASP.NET account. The project compile dfine but on runtime I am getting the attached error. What other permissions do I need to give?

Case "AddToOtl"
                Dim objOutlook As Outlook.Application
                objOutlook = New Outlook.Application
                Dim objNS As Outlook.NameSpace = objOutlook.Session
                '---------Write to Shared calendar-----------------
                'Dim objFolder As Outlook.MAPIFolder = objNS.Folders.Item("Public Folders")
                Dim objFolder As Outlook.MAPIFolder = objNS.Folders.Item("Personal Folders")
                'objFolder = objFolder.Folders.Item("All Public Folders")
                'objFolder = objFolder.Folders.Item("Boss Calendar")
                objFolder = objFolder.Folders.Item("Calendar")
                '=========Add appointment to calendar=================
                Dim objApp As Outlook.AppointmentItem
                objApp = CType(objFolder.Items.Item(Outlook.OlItemType.olAppointmentItem), Outlook.AppointmentItem)
                With objApp
                    .Subject = (" Test appointment")
                    .Location = "Main Office"
                    .Body = ("test appointment")
                    .Start = CDate("10.10.2013 10:00") ' NOTICE: This is my locale date format
                    ' Added a reminder
                    .ReminderMinutesBeforeStart = 60
                    .ReminderSet = True
                    ' Added duration
                    .Duration = 120
                    ' Add logged in Windows user
                    .RequiredAttendees = Environment.UserName
                    ' Save first
                    ' Send to logged in Windows user
                    .Send() ' NOTICE: Outlook security settings may prevent this
                End With
Question by:Angel02
  • 3
  • 3
LVL 10

Expert Comment

by:Asim Nazir
ID: 39514950

Instead of using this approach, better is to implement iCalendar format and simply expose your all feeds/events in this format. It will help you add your events to not only Outlook calendar but also to Google and other calendars that are commonly used today.

For details: http://en.wikipedia.org/wiki/ICalendar

Let me know if you need any other help.

Author Comment

ID: 39519105
Thank you for the response.
Please see my attached code. This is what I did to generate an ics file.

But this code opens the calendar file in an appointment window (screenshot attached) and the user has to click "Save & Close" to save the appointment.

Can this step be skipped so that as soon as the user clicks a button, the event is automatically stored to outlook?

Author Comment

ID: 39519128
I also have to save multiple events at the same time in the calendar. I don't want to open multiple appointment windows like it does now.
Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

LVL 10

Expert Comment

by:Asim Nazir
ID: 39520253

You can do it this way:

1. Create single ics file containing all events.
2. Go to outlook or google calendar and import this ics file.

This will add all events at one and no need to import one by one. I hope it helps.


Author Comment

ID: 39522710
Can you please provide further details of how to do this? Please see attached code. This is what I did. I added another calendar event in the code. When I hit save, it added 2 .ics files as other calendars to my Outlook. Those appointments do not show up on "My Calendar". Please see attached screenshot . You will see several vCalendar[1].ics files towards the left.
LVL 10

Accepted Solution

Asim Nazir earned 2000 total points
ID: 39523775
This and this link should help you further.

Featured Post

Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Often, the users face difficulty in accessing Outlook 2016 PST files on Windows 10 computer. One of the reasons behind it is the improper functioning of MS Outlook when the user tries to open it. MS Outlook suddenly stops working, or it will not op…
Read this tutorial to learn how to fix repeating password error prompts when setting up Gmail IMAP with Microsoft Outlook. The entire process is described with step by step, illustrated instructions. Enjoy...
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question