none
Accessing shared folders within VSTO add-in RRS feed

  • Question

  • I have an add-in that uses emails and tasks pretty much headless to maintain tracking of issues. However it links to my Mailbox, a sub folder within the mailbox and my tasks folder using the lines below.

    olMail = Me.Application.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderInbox)
    olBuilds = olMail.Parent.folders("Builds")
    olTasks = Me.Application.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderTasks)

    My problem is when I'm away everything stops working. A shared setup for mailboxes would fix this as someone can take over. We now have a fake user account called Builder. So I want to attach to Builder's mailbox, the subfolder and task folder and the associated events (NewMailEx etc).

    This however seems to be much more difficult than I'd hoped. The code below seems to create a new recipient not use the current one but I'd assume the other parts would give the result I hope for.

    Dim Recip As Outlook.Recipient = Me.Application.GetNamespace("MAPI").CreateRecipient("HousingBuilder")
    Recip.Resolve()
    olMail = Me.Application.GetNamespace("MAPI").GetSharedDefaultFolder(Recip, Outlook.OlDefaultFolders.olFolderInbox)
    olTasks = Me.Application.GetNamespace("MAPI").GetSharedDefaultFolder(Recip, OlDefaultFolders.olFolderTasks)
    olCal = Me.Application.GetNamespace("MAPI").GetSharedDefaultFolder(Recip, Outlook.OlDefaultFolders.olFolderCalendar)

    As well as searching the task folder I create a task (using the line below) but will it create the task in the default folder or in the shared folder? If the default folder is targeted how do I shift to the shared task folder?

    Dim build As Outlook.TaskItem = Globals.ThisAddin.Application.CreateItem(Outlook.OlItemType.olTaskItem)


    • Edited by _Ritchie_ Friday, December 14, 2012 12:57 PM
    Friday, December 14, 2012 10:14 AM

Answers

  • A task will be created in your default Tasks folder. If you move it to another folder or store you will not get any task updates or reports. You can use code to move it where you choose after it's created.
     
    NewMailEx() will not fire fire for you from the other mailbox. It wouldn't even if you were to open that mailbox as part of your Outlook profile. Try using the ItemAdd() event on the Items collection of that mailbox's Inbox folder.
     
    Creating a recipient for the shared mailbox is the way to do it, unless the mailbox is opened as part of the profile. Then it would be just another Store in the Stores collection. The recipient will do no harm, just release it when you no longer need it.
     
    When you post Outlook programming questions always provide the Outlook version, VS version, and version of VSTO.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "_Ritchie_" <=?utf-8?B?X1JpdGNoaWVf?=> wrote in message news:a877dc74-5b76-4bca-b32d-61beea8ec365...

    I have an add-in that uses emails and tasks pretty much headless to maintain tracking of issues. However it links to my Mailbox, a sub folder within the mailbox and my tasks folder using the lines below.

    olMail = Me.Application.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderInbox)
    olBuilds = olMail.Parent.folders("Builds")
    olTasks = Me.Application.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderTasks)

    My problem is when I'm away everything stops working. A shared setup for mailboxes would fix this as someone can take over. We now have a fake user account called Builder. So I want to attach to Builder's mailbox, the subfolder and task folder and the associated events (NewMailEx etc).

    This however seems to be much more difficult than I'd hoped. The code below seems to create a new recipient not use the current one but I'd assume the other parts would give the result I hope for.

    Dim Recip As Outlook.Recipient = Me.Application.GetNamespace("MAPI").CreateRecipient("HousingBuilder")
    Recip.Resolve()
    olMail = Me.Application.GetNamespace("MAPI").GetSharedDefaultFolder(Recip, Outlook.OlDefaultFolders.olFolderInbox)
    olTasks = Me.Application.GetNamespace("MAPI").GetSharedDefaultFolder(Recip, OlDefaultFolders.olFolderTasks)
    olCal = Me.Application.GetNamespace("MAPI").GetSharedDefaultFolder(Recip, Outlook.OlDefaultFolders.olFolderCalendar)

    As well as searching the task folder I create a task (using the line below) but will it create the task in the default folder or in the shared folder? If the default folder is targeted how do I shift to the shared task folder?

    Dim build As Outlook.TaskItem = Globals.ThisAddin.Application.CreateItem(Outlook.OlItemType.olTaskItem)



    Ken Slovak MVP - Outlook
    Friday, December 14, 2012 6:22 PM

All replies

  • A task will be created in your default Tasks folder. If you move it to another folder or store you will not get any task updates or reports. You can use code to move it where you choose after it's created.
     
    NewMailEx() will not fire fire for you from the other mailbox. It wouldn't even if you were to open that mailbox as part of your Outlook profile. Try using the ItemAdd() event on the Items collection of that mailbox's Inbox folder.
     
    Creating a recipient for the shared mailbox is the way to do it, unless the mailbox is opened as part of the profile. Then it would be just another Store in the Stores collection. The recipient will do no harm, just release it when you no longer need it.
     
    When you post Outlook programming questions always provide the Outlook version, VS version, and version of VSTO.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "_Ritchie_" <=?utf-8?B?X1JpdGNoaWVf?=> wrote in message news:a877dc74-5b76-4bca-b32d-61beea8ec365...

    I have an add-in that uses emails and tasks pretty much headless to maintain tracking of issues. However it links to my Mailbox, a sub folder within the mailbox and my tasks folder using the lines below.

    olMail = Me.Application.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderInbox)
    olBuilds = olMail.Parent.folders("Builds")
    olTasks = Me.Application.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderTasks)

    My problem is when I'm away everything stops working. A shared setup for mailboxes would fix this as someone can take over. We now have a fake user account called Builder. So I want to attach to Builder's mailbox, the subfolder and task folder and the associated events (NewMailEx etc).

    This however seems to be much more difficult than I'd hoped. The code below seems to create a new recipient not use the current one but I'd assume the other parts would give the result I hope for.

    Dim Recip As Outlook.Recipient = Me.Application.GetNamespace("MAPI").CreateRecipient("HousingBuilder")
    Recip.Resolve()
    olMail = Me.Application.GetNamespace("MAPI").GetSharedDefaultFolder(Recip, Outlook.OlDefaultFolders.olFolderInbox)
    olTasks = Me.Application.GetNamespace("MAPI").GetSharedDefaultFolder(Recip, OlDefaultFolders.olFolderTasks)
    olCal = Me.Application.GetNamespace("MAPI").GetSharedDefaultFolder(Recip, Outlook.OlDefaultFolders.olFolderCalendar)

    As well as searching the task folder I create a task (using the line below) but will it create the task in the default folder or in the shared folder? If the default folder is targeted how do I shift to the shared task folder?

    Dim build As Outlook.TaskItem = Globals.ThisAddin.Application.CreateItem(Outlook.OlItemType.olTaskItem)



    Ken Slovak MVP - Outlook
    Friday, December 14, 2012 6:22 PM
  • you can for example use Move function to move task to proper store.
    Friday, December 14, 2012 6:34 PM
  •  Sorry for forgetting my system specs:

    • Outlook Version 2007
    • VS2008
    • whatever VSTO is included with VS2008.

    So could I create the task and move it to the tasks folder of Builder? Then just monitor the Builders task folder?

    I have added the ItemAdd event as an extra handler in case I switch back to default folders later.

    I have the shared mailbox as an additional mailbox to view it in Outlook. I assume the profile would be if it was the attached mailbox for my user account (which it is not)?

    I am still vague on the use of Create recipient though HousingBuilder already exists. Will this create an instance of HousingBuilder or is it a completely new recipient called HousingBuilder?

    Monday, December 17, 2012 2:15 PM
  • yes

    yes

    former

    Monday, December 17, 2012 7:54 PM
  • You can move the task, but it won't be monitored for reports or completion or whatever unless it was created under the context of that mailbox. If you create the task in your own mailbox's default Tasks folder it will be created and monitored there and moving the task will break that monitoring.
     
    It's the same thing with appointments, tallying attendance and so on is only in the default folder and only in the context of the owner/organizer.
     
    Using CreateRecipient() will create a Recipient object for that mailbox owner or delegate. The recipient object is temporary, it doesn't create anything else.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "_Ritchie_" <=?utf-8?B?X1JpdGNoaWVf?=> wrote in message news:670ab58d-7048-412d-af2e-a577cb532bf5...

     Sorry for forgetting my system specs:

    • Outlook Version 2007
    • VS2008
    • whatever VSTO is included with VS2008.

    So could I create the task and move it to the tasks folder of Builder? Then just monitor the Builders task folder?

    I have added the ItemAdd event as an extra handler in case I switch back to default folders later.

    I have the shared mailbox as an additional mailbox to view it in Outlook. I assume the profile would be if it was the attached mailbox for my user account (which it is not)?

    I am still vague on the use of Create recipient though HousingBuilder already exists. Will this create an instance of HousingBuilder or is it a completely new recipient called HousingBuilder?


    Ken Slovak MVP - Outlook
    Tuesday, December 18, 2012 6:44 PM