Close InfoPath Forms Services form using Code
June 3, 2008 Leave a comment
I was working on a way to close an InfoPath form using C# or VB.NET from the form code-behind after the user submits the form. The steps below help in running some custom code to save the data and then close the form.
Here are the steps to close the Form
- Set the Submit Action[Tools->Submit Options] within InfoPath for the form to “Perform custom action using Code” . Click the Edit Code option to submit the form using code
- Set the After Submit option under Advanced to “Close the Form”
Click the Edit Code button next to the perform custom action to submit the data. Editing the code adds an handler for the Form Submit event and a FormEvents_Submit method is created in the code behind. Once the code completes the submission, set the CancelableArgs.Cancel property of the SubmitEventArgs to false.
Here is a sample FormEvents Submit method
In the SubmitConnection method, I retrieve the required data connection and call the execute method for submission
Dim fileSubmit as FileSubmitConnection = CType(Me.Connections(“SharePoint Save”),Microsoft.Office.InfoPath.FileSubmitConnection)
In the above sample, the data connection that I want to use for Submit is named “SharePoint Save”. I typecast it as a FileSubmitConnection.
I found this solution on one of the forum posts