none
How to add an appointment Item to a specific Outlook Calendar irrespective of current Folder RRS feed

  • Question

  • I creating an Appointment Item using Outlook interop using C#.

    I have two accounts configured in my Outlook..I want to save the appointment Item to specific calendar of specific account.

    eg. abc@p5n.com  and xyz@p5n.com are the 2 accounts..for now by default every appointment is being saved in abc@p5n.com..I want all the appointments to saved to xyz@p5n.com..

    Please let me know how could this be achieved.

    Thanks

    Point5Nyble


    Point5Nyble

    Sunday, October 4, 2015 2:33 PM

Answers

  • Hello,

    You need to get the target folder and then use the Add method of the Items class. You can get the required calendar folder using the GetDefaultFolder method of the Store class. This method is similar to the GetDefaultFolder method of the NameSpace object. The difference is that this method gets the default folder on the delivery store that is associated with the account, whereas NameSpace.GetDefaultFolder returns the default folder on the default store for the current profile.

    Finally, you may find the How To: Create a new Outlook Appointment item article helpful. All possible ways of creating Outlook items are described there. 

    Sunday, October 4, 2015 3:45 PM

All replies

  • Hello,

    You need to get the target folder and then use the Add method of the Items class. You can get the required calendar folder using the GetDefaultFolder method of the Store class. This method is similar to the GetDefaultFolder method of the NameSpace object. The difference is that this method gets the default folder on the delivery store that is associated with the account, whereas NameSpace.GetDefaultFolder returns the default folder on the default store for the current profile.

    Finally, you may find the How To: Create a new Outlook Appointment item article helpful. All possible ways of creating Outlook items are described there. 

    Sunday, October 4, 2015 3:45 PM
  • Hi,

    There is no Add method on AppointmentItem..

    Could you please add a snippet to make things a bit more clearer..meanwhile I am reading about Store Class.

    Thanks


    Point5Nyble

    Sunday, October 4, 2015 4:14 PM
  • The article I mentioned earlier provides the following sample code:

    private void CreateAppointmentUsingItemsAdd()
    {
         Outlook.NameSpace ns = null;
         Outlook.MAPIFolder calendarFolder = null;
         Outlook.Items items = null;
         Outlook.AppointmentItem appItem = null;
         try
         {
             ns = Application.GetNamespace("MAPI");
             calendarFolder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
             items = calendarFolder.Items;
             appItem = items.Add(Outlook.OlItemType.olAppointmentItem) as Outlook.AppointmentItem;
             appItem.Save();
             appItem.Display(true);
         }
         catch (Exception ex)
         {
             System.Windows.Forms.MessageBox.Show(ex.Message);
         }
         finally
         {
             if (appItem != null) Marshal.ReleaseComObject(appItem);
             if (items != null) Marshal.ReleaseComObject(items);
             if (calendarFolder != null) Marshal.ReleaseComObject(calendarFolder);
             if (ns != null) Marshal.ReleaseComObject(ns);
         }
    }

    You just need to use the Items collection of the calendar where you need to add an item.

    Sunday, October 4, 2015 4:32 PM
  • Thanks for the sample code ..

    I figured out the way myself after reading your comments..


    Point5Nyble

    Monday, October 12, 2015 7:26 AM
  • Hi Point5Nyble,

    I am glad your issue has been resolved, I suggest you mark the helpful reply as answer to close this thread, and then others who run into the same issue would find the solution quickly.

    Best Regards,

    Edward


    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, October 13, 2015 5:33 AM
  • I am posting the code which I came up with.

    Outlook.Stores oStores = Globals.ThisAddIn.Application.Session.Stores;
                foreach (Outlook.Store store in oStores)
                {
                    try
                    {
                        fldr = store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
                        if (fldr.FolderPath.Contains("products@point5nyble.com"))
                        {
                            if (store.Categories["Critical Dates"] == null)
                            {
                                store.Categories.Add("Critical Dates", Outlook.OlCategoryColor.olCategoryColorBlack, Outlook.OlCategoryShortcutKey.olCategoryShortcutKeyNone);
                            }
                            break;
                        }
                        
                    }
                    catch (Exception)
                    {
                      
                    }
                        
                }

    Thanks


    Point5Nyble

    Tuesday, October 13, 2015 9:46 AM