none
Accessing the Calendar under Personal Folders RRS feed

  • Question

  • Hi,

    I am attempting to read calendar items from Outlook, but I want to read my Calendar from my Personal Folders, not the Exchange folder, and I can't seem to find the syntax to do that.  To be clear, when I am in Outlook and go to Calendar I see three entries under "My Calendars" in the left pane: Calendar, Calendar in Personal Folders, and Calender in Archive Folders.  The default is the Calendar (using the Exchange Calendar).

    Currently I have the following code:

    			oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)
    			'oCalendar = oNS.Folders.Item("Personal Folders")
    			oItems = oCalendar.Items
    
    			' TODO: You may want to use Find or Restrict to retrieve the appointment that you prefer.
    			MsgBox("Calendar Items: " & oCalendar.Items.Count.ToString)
    			MsgBox("First Calendar Item: " & oCalendar.Items(1).ToString)
    
    			' ...
    			For i = 1 To oItems.Count
    				Me.dgvAppointments.Rows.Add()
    				oAppt = oItems.Item(i)
    
    				If TypeOf (oAppt) Is Outlook.AppointmentItem Then
    					Me.dgvAppointments.Rows(i).Cells("Organizer").Value = oAppt.Organizer
    					Me.dgvAppointments.Rows(i).Cells("Subject").Value = oAppt.Subject
    					Me.dgvAppointments.Rows(i).Cells("Location").Value = oAppt.Location
    					Me.dgvAppointments.Rows(i).Cells("StartDate").Value = oAppt.Start.ToString
    					Me.dgvAppointments.Rows(i).Cells("EndDate").Value = oAppt.End.ToString
    				End If
    
    			Next
    

    It only displays the appointments in the Exchange Calendar. I have tried substituting "Personal Folders" (currently commented out), but that doesn't work either. Any help or direction would be appreciated.

    Thanks,

    Don

    Wednesday, December 4, 2013 9:18 PM

All replies

  • Instead of using Namespace.GetDefaultFolder, use Store.GetDefaultFolder, where the Store object is retrieved from the Namespace.Stores collection.

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

    Wednesday, December 4, 2013 9:26 PM
  • Hi Dmitry,

    I have tried this and the Store still only has the one entry (for my ost file) and gets the same folders.

    Also, is there an easier way to debug?  My Outlook client is not on my development machine and I don't want to install VS on my regular desktop (I have it in a VM machine).  Is there an Outlook emulator or do I need to install and configure Outlook on my dev machine to use the VS debugger?

    Thanks.

    Don


    Don DeVeux, Developer

    Friday, December 6, 2013 2:48 PM
  • Hello Don,

    There is no such emulator. Instead, you can create a virtual machine (PC) with Outlook and Visual Studio installed and test your code there.

    It looks like there is no local calendars in the profile (due to the exchange server profile). The Outlook Object Model doesn't provide any other methods for getting default folders.


    Saturday, December 7, 2013 10:38 AM
  • There IS a local folders in my profile, and getting to it IS the issue.  Here is a screen shot of the Calendar view.

    The first entry (unchecked) is the Exchange Calendar.  The second (checked) is the "Calendar in Personal Folders".  I am an independent consultant and work through my own business and through some partners.  One of the partner requires I "look like" them, so they hooked me up to exchange.  All of my other addresses are POP and use the personal folders AND the Calendar in the Personal Folders.  Hence, my problem.  There MUST be a way within the Outlook objects to specify that I want to use this calendar - I just haven't found the object or syntax yet.

    Concerning debugging - yes you are correct and I have installed Outlook on my dev machine and imported my calendar to use it for testing.

    Thanks, Don


    Don DeVeux, Developer

    Monday, December 9, 2013 4:41 PM
  • Hello Don,

    >There MUST be a way within the Outlook objects to specify that I want to use this calendar - I just haven't found the object or syntax yet.

    You may iterate through the folders tree in the store and find the required calendar.

    Monday, December 9, 2013 7:29 PM
  • Here is the current progress.  I have discovered how to access the "Personal Folders" store within Outlook.  However, it is erroring out when I try to use the store to access the Calendar folder.  This works in development because I don't have the strange configuration of Exchange AND Personal folders...just the Personal Folders in dev.  Here's the code:

    oStore = GetPersonalStore(oNS)
    
    oCalendar = oStore.GetDefaultFolder(OlDefaultFolders.olFolderCalendar)
    
    'oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)
    
    
    oItems = oCalendar.Items
    
    The commented statement for oCalendar works, but gives me the Exchange Store.  The GetPersonalStore function gets me the Personal Store, but errors out on the assignment to oCalendar.  I can't tell you the exact error message because I'm not running this in Dev...it just crashes the program (even though it's in a Try...Catch block).


    Don DeVeux, Developer

    Wednesday, December 11, 2013 8:51 PM
  • Hi Don,

    What code does the following function contain?

    GetPersonalStore(oNS)
    

    It looks like you copied separate lines of code from various places. Am I right?

    You can log the exception info to the file. What exception do you get?

    Thursday, December 12, 2013 12:43 PM