none
VSTO Outlook Shared Calendar Access RRS feed

  • Question

  • Hi All

    So I've been searching around, and have been unable to find what I've been looking for.
    Right now I have a VSTO outlook addin which manipulates emails to our needs, and it works perfectly fine.

    I've now been tasked with reading shared calendar and getting information from it.

    So there are around 20 calendars, all attached to a shared mailbox. Everyone has access to these calendars.
    What I need is to be able to click a button. The button would give the option to select one of the 20 calendars attached to the shared mailbox, after selecting, it would then provide information about the attendee of that calendar at that specific time.

    The calendars always have an appointment, 24.7. Each appointment has a different attendee.
    I first need to pull the list of calendars from the mailbox, and get the attendee phone information from GAL (Which I can do, I'm just struggling with being able to access the calendar information in the first place).

    Can I do this? Is there a way of pulling the list of calendars from the shared mailbox, and ultimately pulling further information about the attendee (which is there is only one) from the selected calendar?

    If anyone can provide assistance on this, with some code examples, I would be very much appreciative.

    Thanks

    Wednesday, December 10, 2014 12:15 PM

Answers

  • Hello,

    The Outlook object model provides the GetSharedDefaultFolder method of the Namespace class. It returns a Folder object that represents the specified default folder for the specified user. For example:

    Sub ResolveName()  
     Dim myNamespace As Outlook.NameSpace  
     Dim myRecipient As Outlook.Recipient  
     Dim CalendarFolder As Outlook.Folder 
      
     Set myNamespace = Application.GetNamespace("MAPI")  
     Set myRecipient = myNamespace.CreateRecipient("Dan Wilson")  
     myRecipient.Resolve  
     If myRecipient.Resolved Then  
     Call ShowCalendar(myNamespace, myRecipient)  
     End If  
    End Sub 
    
    Sub ShowCalendar(myNamespace, myRecipient)  
     Dim CalendarFolder As Outlook.Folder 
     Set CalendarFolder = _  
     myNamespace.GetSharedDefaultFolder _  
     (myRecipient, olFolderCalendar)  
     CalendarFolder.Display  
    End Sub

    Also you may find the OpenSharedFolder method of the Namespace class helpful. It allows to open a shared folder referenced through a URL or file name. For example:

    Public Sub OpenSharedHolidayCalendar() 
     Dim oNamespace As NameSpace  
     Dim oFolder As Folder 
     On Error GoTo ErrRoutine 
     Set oNamespace = Application.GetNamespace("MAPI")  
     Set oFolder = oNamespace.OpenSharedFolder( _  
     "webcal://icalx.com/public/icalshare/US32Holidays.ics")  
     oFolder.Display 
    EndRoutine:  
     On Error GoTo 0  
     Set oFolder = Nothing  
     Set oNamespace = Nothing  
    Exit Sub 
    ErrRoutine:  
     MsgBox Err.Description, vbOKOnly, Err.Number & " - " & Err.Source  
     GoTo EndRoutine  
    End Sub

    Wednesday, December 10, 2014 12:48 PM
  • Are you able to acces the shared mailbox iterating over all stores in the profile?

    If not, you need to use the GetSharedDefaultFolder method to get the folder. Then you can try to iterate over all subfolders and find your calendars.

    Wednesday, December 10, 2014 3:48 PM

All replies

  • Hello,

    The Outlook object model provides the GetSharedDefaultFolder method of the Namespace class. It returns a Folder object that represents the specified default folder for the specified user. For example:

    Sub ResolveName()  
     Dim myNamespace As Outlook.NameSpace  
     Dim myRecipient As Outlook.Recipient  
     Dim CalendarFolder As Outlook.Folder 
      
     Set myNamespace = Application.GetNamespace("MAPI")  
     Set myRecipient = myNamespace.CreateRecipient("Dan Wilson")  
     myRecipient.Resolve  
     If myRecipient.Resolved Then  
     Call ShowCalendar(myNamespace, myRecipient)  
     End If  
    End Sub 
    
    Sub ShowCalendar(myNamespace, myRecipient)  
     Dim CalendarFolder As Outlook.Folder 
     Set CalendarFolder = _  
     myNamespace.GetSharedDefaultFolder _  
     (myRecipient, olFolderCalendar)  
     CalendarFolder.Display  
    End Sub

    Also you may find the OpenSharedFolder method of the Namespace class helpful. It allows to open a shared folder referenced through a URL or file name. For example:

    Public Sub OpenSharedHolidayCalendar() 
     Dim oNamespace As NameSpace  
     Dim oFolder As Folder 
     On Error GoTo ErrRoutine 
     Set oNamespace = Application.GetNamespace("MAPI")  
     Set oFolder = oNamespace.OpenSharedFolder( _  
     "webcal://icalx.com/public/icalshare/US32Holidays.ics")  
     oFolder.Display 
    EndRoutine:  
     On Error GoTo 0  
     Set oFolder = Nothing  
     Set oNamespace = Nothing  
    Exit Sub 
    ErrRoutine:  
     MsgBox Err.Description, vbOKOnly, Err.Number & " - " & Err.Source  
     GoTo EndRoutine  
    End Sub

    Wednesday, December 10, 2014 12:48 PM
  • Hi

    Thanks for the info.

    The problem is that these calendars are not shared calendars from a specific person. These are multiple calendars which are all attached to the same shared mailbox.

    We have no way of obtaining the URL to each of the calendars, is there a way of getting the list of all calendar names that are attached to a specific shared mailbox?

    Thanks in advance

    Wednesday, December 10, 2014 1:55 PM
  • Are you able to acces the shared mailbox iterating over all stores in the profile?

    If not, you need to use the GetSharedDefaultFolder method to get the folder. Then you can try to iterate over all subfolders and find your calendars.

    Wednesday, December 10, 2014 3:48 PM

  • If not, you need to use the GetSharedDefaultFolder method to get the folder. Then you can try to iterate over all subfolders and find your calendars.

    And how does one go about doing this?

    I've managed to get the data I need from the default calendar (i.e. my calendar) - I can get all the information, which is great.

    But the calendar I want to access is not the default calendar. It's one of the many listed in my calendars.

    Here is the code I am using to get the information from the default calendar. Note the code is terrible, but it works. 

      Try
    
           
            ' Create the Outlook application.
            Dim oApp As New Outlook.Application()
    
    
                'get namespace
            Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
    
            ' Get the Calendar folder.
                Dim oCalendar As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)
                'Dim oCalendar As Outlook.MAPIFolder = GetUserCalendarFolder("shared name here")
    
            ' Get the Items collection in the folder.
            Dim oItems As Outlook.Items = DirectCast(oCalendar.Items, Outlook.Items)
    
            'Log on by using a dialog box to choose the profile.
            oNS.Logon(Missing.Value, Missing.Value, True, True)
    
    
            ' Get the Items (Appointments) collection from the Calendar folder.
            oItems = oCalendar.Items
            oItems.IncludeRecurrences = True
    
                ' THIS IS THE PROBLEM AREA - Fixed below
            Dim filter As [String] = "[Start] <= '" + DateTime.Now.ToString("yyyy/MM/dd hh:mm AMPM") + "'"
            Dim restrictedItems As Outlook.Items = oItems.Restrict(filter)
            ' Take the last item on the list - should be current or next appointment
            restrictedItems.Sort("[Start]")
            Dim oAppt As Outlook.AppointmentItem = restrictedItems.GetLast()
    
    
            ' Done. Log off.
                oNS.Logoff()
    
                
    
            Dim todaysappointments As String = ""
            Dim currentTime As DateTime = DateTime.Now
            For Each item As Outlook.AppointmentItem In oItems
                If item.Start <= currentTime AndAlso item.[End].Subtract(New TimeSpan(0, 10, 0)) > currentTime Then
                    todaysappointments = todaysappointments & item.RequiredAttendees.ToString() & vbCrLf & item.Subject.ToString() & vbCrLf & item.Body.ToString()
                        'MsgBox(todaysappointments)
                        cname = item.RequiredAttendees.ToString()
                        title = item.Subject.ToString()
                        number = item.Body.ToString()
                        Dim window As New message
                        window.Show()
    
    
                End If
            Next
            Catch ex As System.Exception
    
            End Try
    (Variables are stored elsewhere, so sorry if it doesn't make much sense)

    Now here is the thing.

    I have let's say 5 other calendars, listed in Outlook under my calendars.

    This code will grab information from the default calendar... but ultimately what I need to do is to first

    - Get a combobox (or equivalent) of all the calendars listed in outlook
    - Allow the user to select the Calendar
    - Run the above code on the selected Calendar to grab the information

    I am having a super hard time in getting the list of calendars, and running the above code on a different calendar other than my own default one.

    Any advise?

    Friday, December 26, 2014 12:03 PM
  • Just bumping this, as I'm still a bit stuck :(

    Monday, December 29, 2014 11:06 AM
  • Hi sledgehammer,

    According to the description, you want to get the all shared calendars listed in Outlook.

    Let me try to explain a little more on this.

    First, which information is stored on MAPI, if the shared calendar link is not even stored on MAPI, we are not able to get the info for sure.

    Second, it is the concept of Share Calendar.

    I don't know the inner detail of the share calendar, but the share calendar link is not stored on the MAPI. So when you linked a share calendar (e.g. Jack's calendar) in the Outlook client, it is only the client side operation.

    So, we are able to get the shared item by using the object model, but I don't think we are able to enumerate the linked share items in Outlook, because they are not stored in the MAPI namespace.

    Another thing is why the default calendar does not work. Actually, we can only have on MAPI folder, [alias@domain.com]/Calendar.

    If you want to Oultook object model to support this feature, I suggest that you submit from link below:
    Submit Feedback - Microsoft Office

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, December 31, 2014 7:34 AM
    Moderator
  • Hi Fei

    The calendars I want to list are part of a user account which I have full mailbox access to.

    So they list themselves under My Calendars in outlook. They should be accessible via MAPI.
    To give you a quick understanding, the calendars are here in this screenshot:

    So those calendars I need listed in a ribbon drop down.
    Then once the dropdown has a calendar selected, a button click would apply my above code (in my previous post) on the selected calendar.

    I hope this helps understand what I am looking for.

    Thanks in advance.

    Wednesday, December 31, 2014 8:35 AM
  • Hi sedgehammer,

    Thanks for the detailed explaintation.

    I understand that you want to get the shared calendar folder listed in Outlook canlendar. However, as far as I researched, that we coludn't get the list via Outlook object model since the relative information seems was not stored under the MAPI namespace.

    Also I couldn't find the relative function to achieve the goal via Outlook MAPI, so I suggest that you submit the feedback.

    Hope it is helpful.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, January 1, 2015 1:52 AM
    Moderator
  • I see, thanks for the info, though I still need to find a way of accomplishing what I am after.

    I've heard of Exchange Web Services, is it possible to get the list of all calendars through EWS, and apply the same code that way?

    Monday, January 5, 2015 10:35 AM
  • Hi Seldgehammer,

    >>I've heard of Exchange Web Services, is it possible to get the list of all calendars through EWS, and apply the same code that way?<<

    I am not familar with Exchange developing, to get more effective response I suggest that you reopen a new thread from Exchange Server Development forum.

    Thanks for your understanding.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, January 6, 2015 7:46 AM
    Moderator