In part 1 we created an InfoPath form which used the SharePoint Object Model to create a new Task list item in a SharePoint site.
In this post we’ll publish that form to SharePoint and hook it into the user interface using a content editor web part.
To publish the form, click “Publish Form Template…” on the Design Tasks pane;
Select publish “To a network location” and click OK.
Enter a file path/name for the form to be published to, and enter the published form name. The file/path name you enter must be accessible from the SharePoint web front end at which we’ll upload the published form.
Important: You must clear the alternate form location field here.
Click OK, check the details on the next screen then click Publish to complete the task and a confirmation dialog will display.
Having published the form to a network location we now need to upload the form to SharePoint, to do this we’ll need to go to Central Administration.
Forms with code-behind and/or which require Full Trust are administrator approved forms and must be uploaded to Central Admin by the farm administrator.
In Central Administration go to Application Management and in the InfoPath Forms Services section click “Manage form templates”
Now choose “Upload form template”
Click the browse button and select the published form template (.xsn) file you published previoulsy. Make sure you choose the published form (.xsn) and not the designer (.xsn) form.
If you haven’t previously validated the form you can click Verify here to verify the form is compatible form your SharePoint deployment.
Click the Upload button to upload your form. Once upload is complete you need to activate the form against a site collection, from the Manage Form Templates screen, select Activate to Site Collection from the forms drop-down menu.
Having activated the form to a site collection, we’ll move on to calling the form from a site by using a link embedded on a page using the content editor web part.
It’s important to understand that having activated the form to a site collection, a copy of the form now exists in a special folder in the site collection root web called FormServerTemplates, you can see it in SharePoint Designer, or if you browse to the folder in SharePoint.
Lets begin constructing the link URL. Browser enabled forms are displayed by SharePoint using the FormServer.aspx page which is part of InfoPath Forms Services for SharePoint.
The FormServer.aspx page accepts a number of query string parameters, see the MSDN article How to: Use Query Parameters to Invoke Browser-Enabled InfoPath Forms for more information. Of these query string parameters, we are interested in 4;
- XsnLocation – This parameters is used to specify the location of the forms .XSN file
- SaveLocation – By default this specifies the location to which the submitted form data is saved, in our case we are using this parameter to specify the target site which contain sthe Tasks list we will write to.
- Source – The standard parameter used to specify the location to return to once the submit action completes.
- DefaultItemOpen – See the MSDN article for more information, basically setting this parameter to 1 forces the form to be opened in the browser, this value corresponds to the SPList.DefaultItemOpen property.
Using this information our constructed HTML link tag looks like this (line breaks added for clarity);
<a href="_layouts/FormServer.aspx?XsnLocation=http://portal/FormServerTemplates/TestObjectModelForm.xsn &SaveLocation=http://portal/ &Source=http://portal &DefaultItemOpen=1">Create a new Task.</a>
Paste this code into a content editor web part on a page in your site
Click the link and your form should open, enter the new task title and click Submit
Checking the Tasks list confirms the new task list item.