InfoPath Quick Questions and Answers

Posts Tagged ‘programming infopath

InfoPath repeating table to add, edit, delete SharePoint list items in bulk

While you can create a SharePoint List Form to manage multiple SharePoint list items, it becomes a bit more challenging if you want to do the same using a normal SharePoint Form Library Form.

For the latter, you can write code and make use of the Lists web service to maintain multiple items in a SharePoint list. Such code does not require Full Trust to run, so InfoPath form templates can be normally published to SharePoint Form Libraries as sandboxed solutions.

Recipe 95 of InfoPath 2010 Cookbook 3 and InfoPath 2010 Cookbook 4 gives you the basics of adding items from a repeating table to a SharePoint list, and the Discussion section expands on how to add update and delete functionality to such a solution.

However, you can go a step further and expand the solution in such a way that users can easily add rows to the repeating table, update data in rows of the repeating table, or delete rows from the repeating table, and then when the form is submitted back to SharePoint, all of those inserts, updates, and deletes are written in bulk – so with only one call to the web service – back to the SharePoint list.

The InfoPath 2013 demo video below shows you how such a solution would work.

Source: Bulk insert, update, delete SharePoint list items with InfoPath repeating table


Get data from Excel file attached to InfoPath form

Just like you can store an Excel file in a SharePoint document library, you can also attach an Excel file to a file attachment control on an InfoPath form (browser or Filler).

And just like you can write code to retrieve data from or write data to Excel workbooks that are stored in a SharePoint document library, you can write code to retrieve data from or write data to an Excel workbook that is stored as a file in a file attachment control on an InfoPath form.

The InfoPath video below is a demonstration of recipe 55 of InfoPath 2010 Cookbook 5, in which you will learn how to write C# or Visual Basic .NET code that can retrieve data from cells in an Excel workbook that has been stored in a file attachment control on an InfoPath form.

Source: Retrieve value Excel workbook attached to InfoPath form

Convert InfoPath 2010 to Excel 2010 spreadsheet in SharePoint 2010

While you can set up communication between an InfoPath 2010 form with an Excel spreadsheet that are both hosted in SharePoint 2010 without writing code to transfer data from InfoPath 2010 to Excel 2010, you can also add more flexibility to your InfoPath browser form solutions by writing code in InfoPath 2010 that can transfer data to create an entirely new Excel workbook in SharePoint 2010.

The first solution generally makes use of Excel Services in SharePoint 2010 in combination with the new InfoPath Form Web Part, while for the second solution you can use the Open XML SDK to create a new Excel spreadsheet from scratch based on the data that is stored in an InfoPath browser-enabled form.

For the latter, no programming would be required in SharePoint itself (although you could write either a SharePoint workflow or SharePoint event receiver that creates the Excel workbook from InfoPath data), but all of the code functionality would be contained in the InfoPath form template. In addition, such a form template would not require Full Trust to run, so can be published directly to a SharePoint Form Library using the usual publishing method from within InfoPath Designer 2010.

The following InfoPath video demonstrates an InfoPath browser form solution where repeating table data is used to create a new Excel spreadsheet right on the SharePoint Server and store the Excel file afterwards in a SharePoint document library.

While this solution uses code, there is also a codeless solution to achieve such functionality, that is, permanently store InfoPath repeating table data in an Excel workbook (new or existing) stored in SharePoint.

Source: Convert InfoPath repeating table to Excel 2010 in SharePoint 2010

Chart InfoPath data in SharePoint 2010 using Silverlight

As you may already know, Silverlight integrates nicely with SharePoint 2010. Not only that, but once you get past learning the basics of writing code inside and outside of InfoPath forms as taught in the first 6 chapters of InfoPath 2010 Cookbook 3, you can move onto putting together more interesting and cool solutions such as for example using Silverlight to chart InfoPath data for display in SharePoint 2010.

You can use the Silverlight client object model to access data stored in SharePoint 2010. This same technique also allows you to retrieve data that is stored in SharePoint form libraries, so you can access InfoPath forms and the data they contain from within a Silverlight application.

The Silverlight Toolkit comes with a chart control you can use to display InfoPath data in a chart. So once you have retrieved InfoPath forms and their data from SharePoint, you can then use regular .NET programming techniques in a Silverlight application to display InfoPath data in a chart.

The following video is a demonstration of how you can use Silverlight to retrieve data that is stored in a repeating table in one or several InfoPath forms and then display that data on two different ways in a chart on a SharePoint page.

Source: InfoPath Silverlight chart in SharePoint 2010

Copy repeating table data from InfoPath form to form in SharePoint

Passing data between InfoPath forms generally involves using parameters, whether these parameters are startup parameters (as is the case with InfoPath Filler forms), query string parameters, or web part connection parameters.

In a previous video, you already saw how you can open an InfoPath form from within another InfoPath form and then pass values from one InfoPath form to the other. But what if you already have both InfoPath forms open in SharePoint and you want to pass data between them?

In the InfoPath video shown below, you’ll see how you can use web part connection parameters to pass data from a repeating table on one InfoPath form to another repeating table on a second InfoPath form while both InfoPath 2010 forms are embedded on a page in SharePoint 2010.

Source: Pass repeating table row from one InfoPath form to another in SharePoint

Microsoft Access: Programmatically add new record via InfoPath 2010

While you can directly connect an MS Access database table to an InfoPath form to retrieve and submit data (as shown in InfoPath 2010 Cookbook), it becomes more difficult when you are dealing with a Microsoft Access database table that contains a Memo field.

In such cases, you must write ADO.NET code in InfoPath to be able to not only add new records to the MS Access database, but also update existing records.

Memo fields can contain long text and are suitable to store the text of for example the base64-encoded string of a picture control or the text of a rich text box control on an InfoPath form.

The following InfoPath 2010 video is a demonstration of three solutions in recipe 88 of InfoPath 2010 Cookbook 3 that will teach you how to write C# code to add, update, and delete records in a Microsoft Access database table that contains a Memo field.

Source: Access database CRUD in InfoPath 2010

How to assign a value to a field in InfoPath 2010

There are two ways you can assign a value to a field in InfoPath 2010:

  1. Use a Set a field’s value action rule (without code).
  2. Use the SetValue() method of an XPathNavigator object (with code).

While using rules is the easiest way to assign values to fields, there are occasions on which you would have to use code, for example, when setting the value of fields within a repeating table, because InfoPath does not have an action with which you can set the values of individual fields in a repeating group.

Written by InfoPath Tutor

April 19, 2011 at 11:22 pm