Outlook: Opening the Insert File dialog

I'm writing some small samples to illustrate different VSTO concepts. One is an Outlook add-in that gives you a second chance to add an attachment if the string "attach" appears in the body of the message. If the user chooses to cancel the send and add an attachment, I'd like the Insert File dialog box to open automatically. I have code that's working, but I'm wondering if there's a better way:

                ' Execute the Insert File command button (ID = 777)
                myMailItem.GetInspector.CommandBars.FindControl(, 777).Execute()

This is based on a sample of Sue Mosher's on OutlookCode.com but that sample uses 1079 as the ID. That didn't work (maybe different version of Outlook ) so I used OutlookSpy to find the 777 number. Are there constants that I'm not aware of to make this more readable/robust Or a better way altogether

 



Answer this question

Outlook: Opening the Insert File dialog

  • David Frommer

    Thanks, John. I just wanted to make sure I wasn't missing anything obvious. I'll stick with the the CommandBars technique for Chapter 1, but you've given me a good idea for an enhancement in a later chapter!
    --jan

  • DanHaligas

    Jan,

    There is no way to get a direct reference to the add attachment dialog box to then control its behavior. Going through the CommandBars as Sue suggests is the only way that I know of. For the most part, the IDs should be stable. This is also true for localized versions of the software. That said, I cannot confirm that all of them are constant.

    I would feel at ease using them in a sample, though.

    That said, another technique you can try is to provide your own custom form for selecting the attachment. It's very easy to do (and I know you know how to do that stuff in your sleep, Jan ). Using a simple winform, a filebrowser dialog, a text box, dropdown box, and two buttons, and you have most of the functionality right there.

    I'll consider this answered, but you can re-post if you feel there is something I've overlooked.

    John.



  • Outlook: Opening the Insert File dialog