none
How to get the shared calendar name from shared Addin application RRS feed

  • Question

  • Hi,

    I am working on the Outlook addin application and need to create an appointment in my own calendar as well as the shared calendar in C#.

    I want to get the shared calendar name after I clicked on the calendar and proceeded to create an appointment by code.

    I got the below code to get the shared folder name

    Outlook.NameSpace mNS=mApplication.GetNamespace("MAPI");

    Outlook.Recipient mCalendarRecip = mNS.CreateRecipient("CalendarName");           
    mCalendarRecip.Resolve();
    Outlook.MAPIFolder  mFolder = mNS.GetSharedDefaultFolder(mCalendarRecip, Outlook.OlDefaultFolders.olFolderCalendar);

    But confused how I can get the "CalendarName" to get the 'Recipient' object?

    Another query is that  how can I differentiate  my own calendar and  a shared calendar ?Will the "GetSharedDefaultFolder(....)" method works in my own calendar as well?

    Regards,

    Nirmallya Kolay

    Thursday, June 19, 2014 6:43 AM

Answers

  • Hello Nirmallya,

    > But confused how I can get the "CalendarName" to get the 'Recipient' object?

    The CreateRecipient method of the Namespace class expects to get the name of the recipient; it can be a string representing the display name, the alias, or the full SMTP e-mail address of the recipient, but not the calendar name. I.e. the name of the person (a delegator) who shared the calendar with you. For example, MSDN provides the following sample code:

    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 Folder 
     Set CalendarFolder = _  
     myNamespace.GetSharedDefaultFolder _  
     (myRecipient, olFolderCalendar)  
     CalendarFolder.Display  
    End Sub

    The method can also be used to verify a given name against an address book.

    > Another query is that  how can I differentiate  my own calendar and  a shared calendar ?Will the "GetSharedDefaultFolder(....)" method works in my own calendar as well?

    To get your calendar you can use the following methods:

    Store.GetDefaultFolder - returns a Folder object that represents the default folder in the store and that is of the type specified by the FolderType argument.

    NameSpace.GetDefaultFolder - returns a Folder object that represents the default folder of the requested type for the current profile, for example, obtains the default Calendar folder for the user who is currently logged on. 

    But to get a shared calendar you need to use the NameSpace.GetSharedDefaultFolder method which returns a Folder object that represents the specified default folder for the specified user which you should specify explicitly. Also the NameSpace.OpenSharedFolder method can be used for accessing a shared folder referenced through a URL or file name.

    Finally, you can try to check the Folder.FolderPath property value for all folders.

    Thursday, June 19, 2014 10:41 AM

All replies

  • Hello Nirmallya,

    > But confused how I can get the "CalendarName" to get the 'Recipient' object?

    The CreateRecipient method of the Namespace class expects to get the name of the recipient; it can be a string representing the display name, the alias, or the full SMTP e-mail address of the recipient, but not the calendar name. I.e. the name of the person (a delegator) who shared the calendar with you. For example, MSDN provides the following sample code:

    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 Folder 
     Set CalendarFolder = _  
     myNamespace.GetSharedDefaultFolder _  
     (myRecipient, olFolderCalendar)  
     CalendarFolder.Display  
    End Sub

    The method can also be used to verify a given name against an address book.

    > Another query is that  how can I differentiate  my own calendar and  a shared calendar ?Will the "GetSharedDefaultFolder(....)" method works in my own calendar as well?

    To get your calendar you can use the following methods:

    Store.GetDefaultFolder - returns a Folder object that represents the default folder in the store and that is of the type specified by the FolderType argument.

    NameSpace.GetDefaultFolder - returns a Folder object that represents the default folder of the requested type for the current profile, for example, obtains the default Calendar folder for the user who is currently logged on. 

    But to get a shared calendar you need to use the NameSpace.GetSharedDefaultFolder method which returns a Folder object that represents the specified default folder for the specified user which you should specify explicitly. Also the NameSpace.OpenSharedFolder method can be used for accessing a shared folder referenced through a URL or file name.

    Finally, you can try to check the Folder.FolderPath property value for all folders.

    Thursday, June 19, 2014 10:41 AM
  • Hi Eugene,

    Thanks a lot!

    As MSDN suggested to retrieve the 'Outlook.Recipient' object we are doing "Dan Wilson"  hard coded.

    Set myRecipient = myNamespace.CreateRecipient("Dan Wilson")

    But I need to get the recipient name dynamically after clicking a shared calendar before proceeding to create the appointmentItem.

    I can have more than one shared calendars in the calendar view pane.

    Regards,

    Nirmallya.

    Friday, June 20, 2014 7:53 AM
  • Hello,

    You can try to get the current folder in Outlook using the CurrentFolder property of the Explorer class. Then you can check out the FolderPath property.

    Friday, June 20, 2014 11:43 AM
  • Hi,

    I tried with the CurrentFolder property of the Explorer class and I am getting my calendar and my email address from the FolderPath property.

    But after clicking a particular date/time on a shared calendar I am unable to get the email address of the shared calendar's owner.

    Kindly help me with the code snippet how to retrieve the email address of the shared calendar's owner?

    Thanks a lot!

    Regards,

    Nirmallya.

    Wednesday, July 2, 2014 5:23 AM
  • Hello Nirmallya,

    The Outlook object model doesn't provide any property or method of the Folder class for such things. You can try using Outlook Spy or MFCMAPI utilities for exploring low-level properties.

    Wednesday, July 2, 2014 9:22 AM