Friday, October 9, 2009

InfoPath On a Windows form

In order to load InfoPath form code onto a windows form control, a special control is needed.

The Windows Form control must be displayed prior to loading the code.

NewFromFormTemplate – Use this function to create InfoPath XML.
Open – Use this function to load existing InfoPath XML.

*******************************************************

using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

//%Program Files%\Microsoft Office\Office12\Microsoft.Office.InfoPath.FormControl.dll
using Microsoft.Office.InfoPath;

namespace MyAppNS
{
    public class InfoPathCustomActionPane
    {
        FormControl frmCtrl = new FormControl();
        Form frmDisp = new Form();

        public InfoPathCustomActionPane()
        {
            frmDisp.Size = new Size(600, 400);
            frmDisp.Controls.Add(frmCtrl);

            frmCtrl.Dock = DockStyle.Fill;
        }

        public void DisplayNewInfoPathForm()
        {
            frmDisp.Show();
            frmCtrl.NewFromFormTemplate(@"C:\temp\MyInfoPathForm.xsn");
        }

        public void DisplayExistingInfoPathForm(string xml)
        {
            MemoryStream msXml = new MemoryStream();
            StreamWriter sw = new StreamWriter(msXml);
            sw.Write(xml);
            sw.Flush();
            msXml.Position = 0;

            frmDisp.Show();
            frmCtrl.Open(msXml);
        }
    }
}

No comments:

Post a Comment