• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 425
  • Last Modified:

adding appointment to outlook

I'm using this code to insert appointment to outlook and it works fine.

i have several calendars and it seems to add the appointment into the default
calendar, How do i tell it to put the appointment into some of the other calendars i have in outlook?


this is the code i'm using!

Try
            Dim app As Microsoft.Office.Interop.Outlook.Application
            Dim appt As Microsoft.Office.Interop.Outlook.AppointmentItem
            app = New Microsoft.Office.Interop.Outlook.Application
            appt = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem)

            appt.RequiredAttendees = "somebody@domain.com"
            appt.RequiredAttendees = "somebody@domain.com"
            appt.ForceUpdateToAllAttendees = True
            appt.Recipients.Add("somebody@domain.com")
            appt.Subject = "test Subject"
            appt.Body = "Test body"
            appt.Location = "test Office"
            appt.Start = Convert.ToDateTime("11/12/2010 10:00:00 PM")
            appt.End = Convert.ToDateTime("11/12/2010 11:00:00 PM")
            appt.ReminderSet = True
            appt.ReminderMinutesBeforeStart = 15
            appt.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh
            appt.BusyStatus = Microsoft.Office.Interop.Outlook.OlBusyStatus.olBusy
            appt.Save()
            appt.Send()

        Catch ex As Exception
            Console.WriteLine(ex.ToString())
        End Try
0
jamppi
Asked:
jamppi
  • 3
  • 2
1 Solution
 
David LeeCommented:
Hi, jamppi.

To add an appointment to any calendar other than the default use the Add method of the calendar folder's Items collection.  For example, assuming that the object olkCal represents a calendar folder, then

    Set olkAppt = olkCal.Items.Add()
0
 
jamppiAuthor Commented:
Hi !!

I'm getting "Public member 'Items' on type 'AppointmentItem' not found."

Could you provide a small snippet for that?

/J
0
 
David LeeCommented:
The object you're trying to use Items with is the wrong type.  It's an appointment when it should be a folder.  Here's a the snippet.
Dim olkCal As Outlook.MAPIFolder, olkAppt As Outlook.AppointmentItem
'I used the default calendar as an example. You would replace it with a reference to the folder you want to use.'
Set olkCal = Session.GetDefaultFolder(olFolderCalendar)
Set olkAppt = olkCal.Items.Add

Open in new window

0
 
jamppiAuthor Commented:
Hi!!

it doesnt work!
i'm getting " 'session' is not declared"

i'm using vsto 2010 and office 2010 could that be the problem?

/J
0
 
David LeeCommented:
The code I posted is just a fragment, not a complete solution.  It only shows how to add an item to a non-default folder.  You have to integrate it in with your code.  
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now