Wednesday, February 16, 2011

VSTA Integration with InfoPath

We don't need the VSTA SDK to use VSTA in InfoPath 2007. We need some prerequisites and  make a specific selection in setup:

Microsoft .NET Framework 2.0 (or later) and Microsoft Core XML Services (MSXML) 6.0 must be installed first.

The VSTA development environment is not installed by default when you choose Typical to install InfoPath. To install VSTA, you must either choose Customize when first installing, or use Add or Remove Programs to update your Office or InfoPath installation to include VSTA. The option to install VSTA is available by expanding Microsoft Office InfoPath, .NET Programmability Support, and .NET Programmability Support for .NET Framework version 2.0. The easiest way to do this, is to expand .NET Programmability Support, and then choose Run All From My Computer.

Then, you need to configure your InfoPath form template to use managed code. Open the form template in Design view, click Form Options on the Tools menu, and then click Programming in the Category list. Under Programming, set the Form template code language to either Visual Basic or C#. After doing that, you should have Microsoft Visual Studio Tools for Applications under Tools > Programming.

Testing:

On the InfoPath form 2007 click Button --> Edit Form Code and then start writing the code...
Ex:
//InfoPath SQL Database integration - accessing data from sql through Stored procedures in InfoPath
var serviceid = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:titleauthor/@serviceid").text;

//Set the Command for the Query Adapter of the Data Source. Incorporate the
//parameter values that you want to use.
XDocument.QueryAdapter.Command = 'execute "dbo".""storedprocname" ' + serviceidValue;

//Query the Data Source.
XDocument.Query();

No comments: