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

There are four methods for invoking an InfoPath form or a browser-based version of the form on a server 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 containing the XmlFormView control. The first three types of URL support using query parameters to control aspects of the resulting form, including whether it will be opened in the InfoPath client 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 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.

There are nine different parameters that can be used for opening InfoPath forms. Some parameters override others or cannot be used together, as noted in the table below. 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 from the command line or a batch file using the /InputParameters command-line option, or when a form template is opened from a URL. For more information about using 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 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.

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

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

  • 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 example URLs below. These values represent the following SharePoint and InfoPath items:

  • ServerName: A server running InfoPath Forms Services.

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

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

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

  • NewFolder: A folder within the FormLibrary.

  • NewSite: A site within the SiteCollection.

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

Using a URL with the XmlLocation parameter

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

  2. Create a form 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.

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

Using 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 based on that form template and save it as "Form1" in the library.

  3. Create a new folder in the form library, using the new folder name in place of NewFolder in the URL below.

  4. Create a new site under the existing top-level site collection, using the new site name in place of NewSite in the URL below.

  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, giving it 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.

Using a URL with the OpenIn=Browser parameter

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

  2. Create a form 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 Office InfoPath 2007 installed, the URL forces the form to render in the browser.

Using a URL with the NoRedirect parameter

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

  2. Create a form 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.

Returning a Content Stream

  • Use a URL with the NoRedirect parameter.

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

    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.

See Also

Concepts

Designing Form Templates For Use On A Mobile Device