How to: Use Query Parameters to Invoke Browser-Enabled InfoPath Forms

Applies to: SharePoint Server 2010

There are four methods for invoking an InfoPath form or a browser-based version of the form on a server that is running InfoPath Forms Services. These methods consist of URLs that reference a form template file (.xsn), URLs that reference a form file (.xml) based on a form template, URLs that reference the built-in FormServer.aspx Web page, and those that contain a reference to a custom page that contains the XmlFormView control. The first three kinds of URL support using query parameters to control aspects of the resulting form that includes whether it will be opened in the InfoPath Filler or rendered in the browser, the location where the form will be saved, and the Web page that the user will be directed to when they close the form.

Important

By default, InfoPath forms will open in InfoPath Filler even if a browser-enabled form is available. If InfoPath Filler is not installed, the form will open in the browser. In addition to using query parameters to control how forms are opened, SharePoint form library settings are used to control where forms are opened. To always force the form to open in the browser, open the form library, click the Library tab under Library Tools, click Library Settings on the ribbon, and then click the Advanced settings link under General Settings. Under Opening Documents in the Browser, click Open in the browser.

There are nine different parameters that can be used for opening InfoPath forms. Some parameters override other parameters or cannot be used together, as noted in the following table. Name/value pairs other than those listed in the following table are interpreted as Input Parameters and passed to the form. Input parameters consist of one or more name/value pairs separated by the ampersand (&) character that are specified when a form template is opened in the InfoPath Filler from the command line or a batch file that uses the /InputParameters command-line option, or when a form template is opened from a URL. For more information about how to use input parameters, see the InputParameters property of the LoadingEventArgs class.

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 that is 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 must 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.

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.

DisableSave

SaveLocation

A Save As dialog box is displayed prompting the user for a file name, 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 box is displayed when you are using Internet Explorer.

  • true

  • false (default)

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 Filler 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.

  • 0

  • 1

Note

The query parameters and their associated values are not case-sensitive, but the corresponding properties of the XmlFormView control, such as the Options and SaveLocation properties, are case-sensitive.

Procedures

The following procedures require a site collection that you can publish form templates to, and the ability to create new sites in the site collection.

Placeholder values are used in the following example URLs. These values represent the following SharePoint and InfoPath items:

  • ServerName: A server that is running InfoPath Forms Services.

  • SiteCollection: The top-level site in a site collection.

  • FormLibrary: A form library or document library that contains a browser-enabled form template.

  • Form1.xml: A form that is based on the template.xsn in FormLibrary.

  • NewFolder: A folder within the FormLibrary.

  • NewSite: A site within the SiteCollection.

The ~sitecollection value that is used in the following URLs is not a placeholder value. It is a special token that is used with InfoPath Forms Services that enables relative links and site collection-scoped URL addresses.

To use a URL with the XmlLocation parameter

  1. Create a form template and upload it to a new form library.

  2. Create a form that is based on that form template and save it as "Form1" in the library.

  3. Enter the following URL, inserting actual values for the placeholder values:

    https://ServerName/sites/SiteCollection/_layouts/FormServer.aspx?XmlLocation=~sitecollection/FormLibrary/Form1.xml

    Note

    Note that "Form1" is rendered in the browser.

To use a URL with the XsnLocation, SaveLocation, and Source parameters

  1. Create a form template and upload it to a new form library.

  2. Enter the following URL, inserting actual values for the placeholder values:

    https://ServerName/sites/SiteCollection/_layouts/FormServer.aspx?XsnLocation=~sitecollection/FormLibrary/Forms/template.xsn&SaveLocation=~sitecollection/FormLibrary&Source=~sitecollection/FormLibrary

    Note

    A new form that is based on the form template is rendered in the browser.

  3. Save the new form.

    Note

    The form is saved in the form library specified by the SaveLocation parameter.

  4. Close the form and you will be returned to the form library specified by the Source parameter. In this case, the form library is also where the form is saved because the SaveLocation and Source parameters point to the same location.

To use a URL with the SaveLocation and Source parameters

  1. Create a form template and upload it to a new form library.

  2. Create a form that is based on that form template and save it as "Form1" in the library.

  3. Create a new folder in the form library by using the new folder name to replace NewFolder in the following URL.

  4. Create a new site under the existing top-level site collection by using the new site name to replace NewSite in the following URL.

  5. Enter the following URL, inserting actual values for the placeholder values:

    https://ServerName/sites/SiteCollection/_layouts/FormServer.aspx?XmlLocation=~sitecollection/FormLibrary/Form1.xml&SaveLocation=~sitecollection/FormLibrary/NewFolder/&Source=~sitecollection/NewSite

  6. Save the existing form, typing a new name in the Save As dialog box. The form will be saved in the new folder.

  7. Close the form and you will be redirected to the new site.

To use a URL with the OpenIn=Browser parameter

  1. Create a form template and upload it to a new form library.

  2. Create a form that is based on that form template and save it as "Form1" in the library.

  3. Enter the following URL, inserting actual values for the placeholder values:

    https://ServerName/sites/SiteCollection/FormLibrary/Form1.xml?OpenIn=Browser

    or

    https://ServerName/sites/SiteCollection/_layouts/FormServer.aspx?XmlLocation=~sitecollection/FormLibrary/Form1.xml&OpenIn=Browser

    Note

    Even if you have Microsoft InfoPath 2010 installed, the URL forces the form to render in the browser.

To use a URL with the NoRedirect parameter

  1. Create a form template and upload it to a new form library.

  2. Create a form that is based on that form template and save it as "Form1" in the library.

  3. Enter the following URL, inserting actual values for the placeholder values:

    https://ServerName/sites/SiteCollection/FormLibrary/Form1.xml?NoRedirect=true

    and

    https://ServerName/sites/SiteCollection/FormLibrary/Forms/template.xsn?NoRedirect=true

    Note

    The form file (.xml) and the form template (.xsn) will not be redirected to FormServer.aspx. Instead, you will be presented with the File Download dialog box (if using Internet Explorer) to download the file from the SharePoint site.

It is sometimes necessary to return a content stream of the XML representing the form. This is possible using the following methods.

To use a content stream

  • Use a URL with the NoRedirect parameter.

  • Insert a "Translate:f" header in the HTTP GET request, such as the following example:

    myRequest.Headers.Add("Translate:f");
    myRequest.Headers["Translate"] = "F";
    
  • Use the appropriate InfoPath user agent in the HTTP GET request, InfoPath.1 or InfoPath.2.