Introduction
When creating a hyperlink to open a new InfoPath form, you need to identify the hyperlink as created by SharePoint and then modify the query string portion of the hyperlink to execute your expected behavior. You should have a basic understanding of URL Syntax (Wikipedia) and specifically the Query String (Wikipedia) portion of a URL.
By default, InfoPath forms will open in InfoPath even if a browser-enabled form is available. If InfoPath is not installed, the form will open in the browser. In addition to using query parameters to control how forms are opened, SharePoint library settings are used to control where forms are opened. To always force the form to open in the browser, choose Display as a Web page on the library's Advanced Settings page.
Structure of InfoPath URL
The generic structure of the URL used to invoke browser-enabled InfoPath forms is:
Breaking out the query string components of the URL, we have:
- XsnLocation=http://servername/FormLibrary/Forms/template.xsn
- SaveLocation=/FormLibrary
- DefaultItemOpen=1
- OpenIn=Browser
- Source=/Pages/ThankYouPage.aspx
These parameters are each important in ensuring the user opens the right form (with a browser), the contents of which are saved in the proper location and the user is directed to the right page upon closing the form.
Procedures
In order to determine the URL to invoke your browser-enabled InfoPath form, you must have created a Form Library and uploaded a (blank) form as the library template. In addition, the library's advanced settings must be updated to always force the form to open in a browser (see Introduction of this page).
Rather than creating the URL yourself, it's often easier to let SharePoint start the hard part for you. To do this, navigate to your Form Library and click the New button, opening your form in a browser window. Notice the complete URL to the form in your web browser's address bar. Copy this URL to a text editing application (such as Notepad).
For Example:
Looking at the URL you will see that the structure matches what's describe above. You'll also notice that the values for the query string parameters are not as "clean" as those described above. This is because some of the parameters have been URL encoded (see URL Encoding (Wikipedia) for more details). You may also notice that the OpenIn parameter is not included by default.
You're likely to only need to update (or add) the following parameters:
- OpenIn=Browser
- Source=/Pages/ThankYouPage.aspx
Note: If you remove the Source parameter, upon closing the form the user will be redirected to the page hosting the URL hyperlink.
However, when it comes time to use this URL within a SharePoint Links list, you may find that the length of your URL is too long (SharePoint Links Lists allow a maximum of 255 characters for URLs, including "http://", giving you an effective maximum length of 248 characters). One way to keep reduce length of your URL is to remove the http://servername portion of the following parameters:
- XsnLocation=/FormLibrary/Forms/template.xsn
- SaveLocation=/FormLibrary
- Source=/Pages/ThankYouPage.aspx
More Information
For more information about using query string parameters to invoke browser-enabled InfoPath forms, please visit this MSDN Article (Microsoft).
In addition, the table below (copied from the MSDN article) can be helpful:
|
Parameter Name |
Description |
Allowed Values |
|
XmlLocation |
Used to open an existing form. The XmlLocation and XsnLocation properties are mutually exclusive; specifying values for both parameters will result in an error. |
A valid URL to a form file (.xml) in the same site collection. |
|
XsnLocation |
Used to open a new form based on a form template. If an XsnLocation is specified in a URL using FormServer.aspx, a SaveLocation should also be specified if the Save and Save As buttons need to be displayed. The Source parameter should also be specified or the message "The form has been closed" will appear when the user closes the form. The XmlLocation and XsnLocation properties are mutually exclusive; specifying values for both parameters will result in an error. |
A valid URL to a form template file (.xsn) published on the same site collection. |
|
OpenIn |
-
If a Source query parameter is specified, the default value is Browser.
-
If XmlLocation is specified, the default value is the setting used in the library.
-
If only XsnLocation is specified, the default value is PreferClient.
-
If Mobile is specified, the form will be redirected to the MobileFormServer.aspx page for rendering. The form template must be enabled for mobile support or an error message will be returned. |
-
Browser
-
Client
-
PreferClient
-
Mobile |
|
Source |
The location to which the user will be redirected when the form is closed. The URL must be in the same site collection or an error will be returned. |
A valid URL in the same site collection as the form.
[Added by Mike Geyer]: A blank value will return the user to the referring page (where the link to the form is hosted). |
|
Options |
DisableSave is the only allowed value. It hides the Save and Save As buttons and disables saving the form when it is rendered in the browser. |
|
|
SaveLocation |
A Save As dialog box is displayed prompting the user for a filename, and then it is saved in the specified folder. An error is returned if the specified folder does not exist. |
Any valid folder location on the site collection. |
|
NoRedirect |
Does not redirect to FormServer.aspx for client detection or rendering in the browser. Default value is false. If true and an XmlLocation or XsnLocation is specified, a File Download dialog is displayed when using Internet Explorer. |
|
|
DefaultItemOpen |
The OpenIn parameter should be used instead, and overrides the DefaultItemOpen parameter value. A value of 0 indicates that the request is from a document library and the InfoPath client was not detected. A value of 1 indicates that the request is from a document or form library that has the Display as a Web page setting. |
|