Monday, January 22, 2007

Creating Custom Taskpanes with .NET User Controls in VSTO

Developing InfoPath Add-In

With VSTO 2005 (Visual Studio Tools for Office) you can easily create InfoPath add-ins!
Watch ...

  • First download VSTO on the Microsoft website (free download)
  • After installation, start up Visual Studio 2005 and select the InfoPath2007 add-in as template.
  • In your project contains 2 methods:
    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    private void ThisAddIn_Shutdown(object sender, System.EventArgs e)

  • Since InfoPath 2007 we can use .NET User Controls as Custom Task Pane. In InfoPath 2003 we had to use JavaScript, ASP.NET or HTML files. We can also use help files (CHM files) as custom task pane.
  • Add a new Item to your project (User Control)You can add Windows controls to this User Control.

  • To show the Custom TaskPane we have to add some code to the ThisAddIn_Startup method.In the Startup method you call the CreateCustomPane() method below:

    private TaskPaneUC tpuc;

    private void CreateCustomPane()
    this.tpuc = new TaskPaneUC();
    this.tpuc.submitEvent += new TaskPaneUC.OnSubmit(tpuc_submitEvent);
    this.tpuc.switchViewEvent += new TaskPaneUC.OnSwitchView(tpuc_switchViewEvent);
    this.tpuc.exitEvent += new TaskPaneUC.OnExit(tpuc_exitEvent);

    this.ctp = this.CustomTaskPanes.Add(tpuc, "Happy 2007");
    this.ctp.Visible = true;
  • For redirecting button actions to the ThisAddIn.cs we use delegates and events.

    public delegate void OnSubmit(object sender, SubmitArgs args);
    public event OnSubmit submitEvent;

    private void CreateCustomPane()
    this.tpuc.submitEvent += new TaskPaneUC.OnSubmit(tpuc_submitEvent);
  • Through the User control in this example you can do the following tasks

    • Set a field’s value
    • Switch View

    • Exit application

      Download this example here.

    Installing the InfoPath Add-In

    The add-in will be automatically installed when debugging the application.
    For deployment you can use the Setup project which will be added automatically to your project.

    Uninstalling the InfoPath Add-In

    When you move the InfoPath Add-In project to another location, the Add-in will be automatically deactivated.

    Overview of InfoPath Add-In

    1. Open InfoPath 2007.
    2. Go to the Help menu and select 'Privacy Options'

    No comments: