none
Create Event in Office 365 Outlook Calendar with vb.net using Microsoft Graph RRS feed

  • Question

  • I currently have a Procedure written in vb.net which Adds Entries to Outlook 2007 Shared Calendars.

    Imports Outlook = Microsoft.Office.Interop.Outlook

    Public Sub UpdateCalendar(ByVal subject As String, ByVal body As String, ByVal startdate As Date, ByVal enddate As Date, ByVal location As String, ByVal dept As String)

            Dim objApp As New Outlook.Application
            Dim objNS As Outlook.NameSpace
            Dim objFolder As Outlook.MAPIFolder
            Dim objDummy As Outlook.MailItem
            Dim objRecip As Outlook.Recipient
            Dim objAppt As Outlook.AppointmentItem
            Dim strMsg As String = Nothing
            Dim strName As String = Nothing
            Dim d As New DBRequest
            Dim Calendar As String = Nothing

            Calendar = d.GetCalendarEmail(dept)
            If Calendar = "No Calendar" Then
                MsgBox("No Calendar is associated with this user. Contact  IT Department to resolve this issue.", vbOKOnly, TITLE)
                Exit Sub
            End If

            Try
                objNS = objApp.GetNamespace("MAPI")

                objRecip = objNS.CreateRecipient(Calendar)
                objRecip.Resolve()

                objFolder = objNS.GetSharedDefaultFolder(objRecip, Outlook.OlDefaultFolders.olFolderCalendar)
                objAppt = objFolder.Items.Add

                With objAppt
                    .Subject = subject
                    .Body = body + "" + vbCrLf + location
                    .Start = Convert.ToDateTime(startdate)
                    .End = Convert.ToDateTime(enddate)
                    .Save()
                End With


            Catch ex As Exception

                objFolder = Nothing
                objAppt = Nothing
                objRecip = Nothing
            End Try

            objNS = Nothing

            objApp = Nothing
            objNS = Nothing
            objFolder = Nothing
            objDummy = Nothing
            objRecip = Nothing
            objAppt = Nothing
            d = Nothing

        End Sub

    My company is upgrading to Office 365 and I need to add entries to Outlook 365 shared Calendars in the same manner.

    Can anyone help?


    KS


    KS

    Friday, December 15, 2017 4:19 PM

All replies

  • I currently have a Procedure written in vb.net which Adds Entries to Outlook 2007 Shared Calendars.

    Imports Outlook = Microsoft.Office.Interop.Outlook

    Public Sub UpdateCalendar(ByVal subject As String, ByVal body As String, ByVal startdate As Date, ByVal enddate As Date, ByVal location As String, ByVal dept As String)

            Dim objApp As New Outlook.Application
            Dim objNS As Outlook.NameSpace
            Dim objFolder As Outlook.MAPIFolder
            Dim objDummy As Outlook.MailItem
            Dim objRecip As Outlook.Recipient
            Dim objAppt As Outlook.AppointmentItem
            Dim strMsg As String = Nothing
            Dim strName As String = Nothing
            Dim d As New DBRequest
            Dim Calendar As String = Nothing

            Calendar = d.GetCalendarEmail(dept)
            If Calendar = "No Calendar" Then
                MsgBox("No Calendar is associated with this user. Contact  IT Department to resolve this issue.", vbOKOnly, TITLE)
                Exit Sub
            End If

            Try
                objNS = objApp.GetNamespace("MAPI")

                objRecip = objNS.CreateRecipient(Calendar)
                objRecip.Resolve()

                objFolder = objNS.GetSharedDefaultFolder(objRecip, Outlook.OlDefaultFolders.olFolderCalendar)
                objAppt = objFolder.Items.Add

                With objAppt
                    .Subject = subject
                    .Body = body + "" + vbCrLf + location
                    .Start = Convert.ToDateTime(startdate)
                    .End = Convert.ToDateTime(enddate)
                    .Save()
                End With


            Catch ex As Exception

                objFolder = Nothing
                objAppt = Nothing
                objRecip = Nothing
            End Try

            objNS = Nothing

            objApp = Nothing
            objNS = Nothing
            objFolder = Nothing
            objDummy = Nothing
            objRecip = Nothing
            objAppt = Nothing
            d = Nothing

        End Sub

    My company is upgrading to Office 365 and I need to add entries to Outlook 365 shared Calendars in the same manner.

    Can anyone help?


    KS

    Friday, December 15, 2017 1:15 PM
  • I think you're going to have to delve into Exchange Web Services for this. You may want to look at the code examples from the below link to see if there is something you can use:

    https://code.msdn.microsoft.com/office/Exchange-2013-101-Code-3c38582c/view/SamplePack#content

    Some more info:

    https://msdn.microsoft.com/en-us/library/office/dd633626(v=exchg.80).aspx

    You may also want to post to the Exchange Server Developer forum:

    https://social.technet.microsoft.com/Forums/exchange/en-US/home?forum=exchangesvrdevelopment


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Friday, December 15, 2017 3:24 PM
  • Hi kstarkes,

    Since this forum is discussing and asking questions about the Visual Basic programming language, IDE, libraries, samples, and tool, and your issue is more related to outlook for developer, I will move this thread to the more related forum.

    Thanks for your understanding and support.

    Best Regards,

    Cherry



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 18, 2017 2:44 AM
  • Your code should still work fine as long as the current user in Outlook has access to the other user's folder.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!


    Monday, December 18, 2017 3:49 AM
  • Hi KS,

    According to your description, your query is more related to developing issues about Outlook. Then here we mainly focus on general issues about Office client, so I'll move your thread to the dedicated MSDN forum for Outlook for better response. 

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    Best regards,
    Yuki Sun


    Please remember to mark the replies as answers if they helped.
    If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Monday, December 18, 2017 5:28 AM
  • Hello KS,

    What error do you get using the code above?

    Could you manually create appointment for the shared calendars? If you fail to create appointment manually, please check if you have permission to create items.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 20, 2017 2:16 AM
    Moderator