none
Outlook 2013 VSTO Inline Response Wrapper RRS feed

  • Question

  • I have an Outlook Inspector Wrapper class to handle Ribbon Togglebutton states.  This works well.  I'm now looking at the Inline Message as I need to keep the state of the Togglebutton for each Draft.  I'm thinking of using the InlineResponse event but am not sure what exactly I'm wrapping, item EntryID?  Is it possible, for the current session, to keep track of Ribbon Togglebutton states for Inline Messages?  (If the user closes Outlook, those states would of course be lost, unless it can be saved with the Draft.) 

    Private Sub WrappedInlineWindow_InlineResponse(ByVal item as Object)
         If TypeOf item is Outlook.MailItem Then
              Wrap_Explorer(????)
         End If
    End Sub


    • Edited by J Wagner Sunday, July 7, 2013 3:55 PM
    Sunday, July 7, 2013 2:43 AM

Answers

  • I'd wrap the items, or rather each MailItem that you want to track. It would be similar to an Items wrapper that tracked Items collections from folders of interest. Using EntryID would be good for that as a key.

    Ken Slovak MVP - Outlook

    Tuesday, July 9, 2013 3:33 PM
  • Hi J Wanger,

    According to your description, I think you are looking for some place to save states for each mail item.

    If so, MailItem.UserProperties could be a proper choice.

    Below is a code sample about how to set/get custom values in a mail item:

    Public Class ThisAddIn
    
        Private Sub ThisAddIn_Startup() Handles Me.Startup
            SetCustomValueToFirstMailItem()
            GetCustomValueFromFirstItem()
        End Sub
    
        Private Sub SetCustomValueToFirstMailItem()
            Dim nsp As Outlook.NameSpace
            Dim folder As Outlook.Folder
            Dim item As Outlook.MailItem
            Dim prop As Outlook.UserProperty
    
            nsp = Application.GetNamespace("MAPI")
            folder = nsp.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
            item = folder.Items.GetFirst()
            prop = item.UserProperties.Add("CustomProp", Outlook.OlUserPropertyType.olText)
            prop.Value = "SaveStateHere"
    
            item.Save()
        End Sub
    
        Private Sub GetCustomValueFromFirstItem()
            Dim nsp As Outlook.NameSpace
            Dim folder As Outlook.Folder
            Dim item As Outlook.MailItem
            Dim prop As Outlook.UserProperty
    
            nsp = Application.GetNamespace("MAPI")
            folder = nsp.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
            item = folder.Items.GetFirst()
            prop = item.UserProperties.Find("CustomProp")
    
            Dim val = prop.Value
        End Sub
    
    
        Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
    
        End Sub
    
    End Class
    

    Friday, July 12, 2013 6:22 AM
    Moderator
  • The purpose of wrapping things is so you can handle more than one thing at a time. For example open Inspectors, open Explorers, Items collections in specific folders, and so on.

    In those cases you use a class that has an instance of the thing you are wrapping. The class would also implement handler code for each event you want to handle for that thing.

    For inline responses you are handling either the item in the ActiveExplorer().Selection, or an item opened from the Selection as an opened inline response.

    I would add a new instance of the wrapper class to a list/collection/dictionary/whatever when the inline response event fired and remove the class instance when the item was sent or closed or Selection changed without opening an item. The constructor code for the wrapper class should add the handler when the class is created, and dispose code in the class would remove the handler as part of the class cleanup, when the class is removed from the wrapper collection.


    Ken Slovak MVP - Outlook

    Monday, July 15, 2013 3:08 PM

All replies

  • Hi JWagner,

    Thank you for posting in the MSDN Forum.

    I'm trying to involve some senior engineers into this issue and it will take some time. Your patience will be greatly appreciated.

    Sorry for any inconvenience and have a nice day!

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, July 9, 2013 1:46 PM
    Moderator
  • I'd wrap the items, or rather each MailItem that you want to track. It would be similar to an Items wrapper that tracked Items collections from folders of interest. Using EntryID would be good for that as a key.

    Ken Slovak MVP - Outlook

    Tuesday, July 9, 2013 3:33 PM
  • Hi J Wanger,

    According to your description, I think you are looking for some place to save states for each mail item.

    If so, MailItem.UserProperties could be a proper choice.

    Below is a code sample about how to set/get custom values in a mail item:

    Public Class ThisAddIn
    
        Private Sub ThisAddIn_Startup() Handles Me.Startup
            SetCustomValueToFirstMailItem()
            GetCustomValueFromFirstItem()
        End Sub
    
        Private Sub SetCustomValueToFirstMailItem()
            Dim nsp As Outlook.NameSpace
            Dim folder As Outlook.Folder
            Dim item As Outlook.MailItem
            Dim prop As Outlook.UserProperty
    
            nsp = Application.GetNamespace("MAPI")
            folder = nsp.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
            item = folder.Items.GetFirst()
            prop = item.UserProperties.Add("CustomProp", Outlook.OlUserPropertyType.olText)
            prop.Value = "SaveStateHere"
    
            item.Save()
        End Sub
    
        Private Sub GetCustomValueFromFirstItem()
            Dim nsp As Outlook.NameSpace
            Dim folder As Outlook.Folder
            Dim item As Outlook.MailItem
            Dim prop As Outlook.UserProperty
    
            nsp = Application.GetNamespace("MAPI")
            folder = nsp.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
            item = folder.Items.GetFirst()
            prop = item.UserProperties.Find("CustomProp")
    
            Dim val = prop.Value
        End Sub
    
    
        Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
    
        End Sub
    
    End Class
    

    Friday, July 12, 2013 6:22 AM
    Moderator
  • Thanks for your responses.  In the ThisAddIn_Startup event, I add a handler for the explorer inlineresponse as follows:

    AddHandler my_Explorer.InlineResponse, AddressOf WrappedInlineWindow_InlineResponse

    In the WrappedInlineWindow_InlineResponse, I do the wrapping using the EntryID.  I remove the MailItem EntryID from the list, in the ItemSend event (if it's an ActiveInlineResponse object).  Do I remove this handler in the Shutdown event?

    Jeffrey:

    Thanks for directing me to UserProperties.  I will implement the code.

     
    • Edited by J Wagner Monday, July 15, 2013 5:14 AM put code in block
    Monday, July 15, 2013 5:12 AM
  • The purpose of wrapping things is so you can handle more than one thing at a time. For example open Inspectors, open Explorers, Items collections in specific folders, and so on.

    In those cases you use a class that has an instance of the thing you are wrapping. The class would also implement handler code for each event you want to handle for that thing.

    For inline responses you are handling either the item in the ActiveExplorer().Selection, or an item opened from the Selection as an opened inline response.

    I would add a new instance of the wrapper class to a list/collection/dictionary/whatever when the inline response event fired and remove the class instance when the item was sent or closed or Selection changed without opening an item. The constructor code for the wrapper class should add the handler when the class is created, and dispose code in the class would remove the handler as part of the class cleanup, when the class is removed from the wrapper collection.


    Ken Slovak MVP - Outlook

    Monday, July 15, 2013 3:08 PM