none
How to create replacement or replace-all outlook form regions RRS feed

  • Question

  • Hello,

    I have created a 2010 add-in project for Outlook. It has a ribbon created from the designer and Outlook form regions for separate and adjoining types, both of which are attached to the Mail Message class (the default IPM.Note). The adjoining form shows just below new mail messages. The separate form shows as an icon on a new mail message, and when clicked swaps out the standard email form for mine.

    No problems there.

    My question is about how to implement replacement or replace-all outlook form regions. Where do these show? How to create these so that when you click a custom button in the ribbon the form is shown?

     

    Thanks,

    Aaron

    Wednesday, March 11, 2015 2:24 PM

Answers

  • Aaron,

    > or is that why example code like above is popping out a new mail item?

    Here is the answer to the questions:

    item.Display(false);

    > Do you know off-hand if you can hide the explorer  (current view) and then display the form inits place?

    It is not clear what you are talking about. Do you want to show the form instead of the table view in Outlook?

    If so, VSTO (nor Outlook) doesn't provide anything for that. You need to use Windows API functions to subclass Outlook windows to inject the form there. See Adjacent Windows In Outlook for more information.

    You may find the WebViewURL and WebViewOn properties of the Folder class helpful. They allow to show a home page for the folder. For example:

    Sub SetupFolderHomePage()  
     Dim nsp As Outlook.NameSpace  
     Dim mpfInbox As Outlook.Folder  
     Dim mpfNew As Outlook.Folder 
     
     Set nsp = Application.GetNamespace("MAPI")  
     Set mpfInbox = nsp.GetDefaultFolder(olFolderInbox)  
     Set mpfNew = mpfInbox.Folders.Add("MyFolderHomePage")  
     mpfNew.WebViewURL = "http://www.microsoft.com"  
     mpfNew.WebViewOn = True  
    End Sub

    • Marked as answer by azeeriley Thursday, March 12, 2015 1:41 PM
    Wednesday, March 11, 2015 4:56 PM

All replies

  • Hello Aaron,

    They are used to replace the inspector view with your own controls. VSTO doesn't provide any way to show or hide them dynamically (when you click a ribbon button). Instead, you need to close the inspector window, change the message class and then re-open the inspector window. Only in that case you can switch back to the normal view. They can be associated only with custom message classes. As you may see the standard message classes are greyed out on the dialog:

    As a workaround, you may consider using Advanced form regions from ADX, they allow to switch the view dynamically.

    Wednesday, March 11, 2015 3:44 PM
  • Thanks for the help Eugene!

    I think I understand how this works now.

    A few notes on how to create an Outlook Form Region with replace option:

    - create new outlook form region

    - call it something like IPM.Note.Contoso (by default will inherit properties of IPM.Note unless you break from the namespace)

    - add some controls to it

    - add below (or similar) to your ribbon button event

    private void button1_Click(object sender, RibbonControlEventArgs e)
            {
                //System.Windows.Forms.MessageBox.Show("Your Ribbon Works!");

                // GET CONTEXT
                Outlook.Explorer explorer = (Outlook.Explorer)this.Context;
                
                // CREATE ITEM
                Outlook.MailItem item = explorer.Application.CreateItem(Outlook.OlItemType.olMailItem);
                item.MessageClass = "IPM.Note.Contoso";
                item.Display(false);

            }

    I'll continue working on this. Do you know off-hand if you can hide the explorer  (current view) and then display the form inits place? or is that why example code like above is popping out a new mail item?

    Aaron
    Wednesday, March 11, 2015 4:42 PM
  • Aaron,

    > or is that why example code like above is popping out a new mail item?

    Here is the answer to the questions:

    item.Display(false);

    > Do you know off-hand if you can hide the explorer  (current view) and then display the form inits place?

    It is not clear what you are talking about. Do you want to show the form instead of the table view in Outlook?

    If so, VSTO (nor Outlook) doesn't provide anything for that. You need to use Windows API functions to subclass Outlook windows to inject the form there. See Adjacent Windows In Outlook for more information.

    You may find the WebViewURL and WebViewOn properties of the Folder class helpful. They allow to show a home page for the folder. For example:

    Sub SetupFolderHomePage()  
     Dim nsp As Outlook.NameSpace  
     Dim mpfInbox As Outlook.Folder  
     Dim mpfNew As Outlook.Folder 
     
     Set nsp = Application.GetNamespace("MAPI")  
     Set mpfInbox = nsp.GetDefaultFolder(olFolderInbox)  
     Set mpfNew = mpfInbox.Folders.Add("MyFolderHomePage")  
     mpfNew.WebViewURL = "http://www.microsoft.com"  
     mpfNew.WebViewOn = True  
    End Sub

    • Marked as answer by azeeriley Thursday, March 12, 2015 1:41 PM
    Wednesday, March 11, 2015 4:56 PM
  • Perfect!

    Exactly what I was looking for. Just needed to know what is usually done to extend outlook to include a form. Both look promising and I think I will also try custom task panes as an approach.

    Thanks again Eugene!

    Wednesday, March 11, 2015 6:18 PM
  • Hopefully last question on this one.

    Made some progress.

    The below code does add a new folder with the below:

    		private void button1_Click(object sender, RibbonControlEventArgs e)
    		{
    			//System.Windows.Forms.MessageBox.Show("Your Ribbon Works!");
    
    			//ShowReplacementFormRegion();
    
    			//ShowReplaceAllFormRegion();
    
    			SetUpFolderHomepage("MyHomePageFolder", "http://google.com");
    			
    
    		}
    		private void SetUpFolderHomepage(string foldername, string url)
    		{
    			Outlook.NameSpace nsp = Globals.ThisAddIn.Application.GetNamespace("MAPI");
    			Outlook.MAPIFolder inbox = nsp.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
    			Outlook.MAPIFolder f = inbox.Folders.Add(foldername);
    			f.WebViewURL = url;
    			f.WebViewOn = true;
    		}

    Is it possible to also redirect or set focus to this new panel?

    Aaron

    Wednesday, March 11, 2015 9:10 PM
  • I'd recommend creating a new forum threads for separate questions. Thus, forum readers may recognize questions and answers easily. 

    You are free to use Windows API functions for setting focus wherever you need.

    Wednesday, March 11, 2015 9:15 PM
  • my apologies. thanks for your help :)
    Thursday, March 12, 2015 1:41 PM