Skip to main content

Mike Geyer's Blog

A fun place to read and collaborate about SharePoint and related technologies.
Go Search
  

Keep in touch: RSS Feed  


I'm a


My company is a


And we deliver

  (we're certified)
Mike Geyer's Blog > Posts > Creating a Hyperlink to an InfoPath Form
Creating a Hyperlink to an InfoPath Form
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.

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

Comments

Thanks and one more question

Hi,

I was very happy when I found this post as it explained exactly what I was looking for.  The link is now working and the form is displayed when the hyperlink is clicked.  What I can't do however is to prepopulate the form with some data from the list item whose hyperlink I clicked.  I googled for days but all I could find was the use of secondary data connections that bring _all_ list data. Nowhere could I find how to get the data for a specific (current? selected?) list item.  Any chance you could help? Thanks...
at 8/9/2009 4:00 PM

Re: Anna

Hello Anna,

I'm glad you found this post helpful.  Unfortunately I have never found a way to pass parameters into an InfoPath form either... well, that's mostly true.  I did have a colleague write a custom InfoPath-hosting web part that has two great features:
1. It supports pulling parameters from the query string and making them useful within an InfoPath from
2. It acutually hosts the InfoPath form within the web part so you can maintain the look and feel of the web site (rather than having InfoPath take over the whole browser window).

Unfortunately I'm not able to share the code, but it can be done with a C# programmer.

Best of luck!

 - Mike
at 8/9/2009 4:00 PM

Thanks for the post!

I was searching for this answer. Thanks so much. It works a treat!
at 8/9/2009 4:00 PM

 All Posts

Creating a SP List via Excel - Import from Spreadsheet
I've Moved to Hitachi Consulting
SharePoint 2010 Sneak Peak!
Business Intelligence During an Uncertain Time
Keeping In Touch with Family Around the US
Using Javascript to Manipulate a List Form Field
How to Use JavaScript to access SharePoint Query String
First Blog with Windows Live Writer
Microsoft to offer free classes and certification testing
Job Description - SharePoint Solution Architect
SharePoint Blogs as Status Reporting... and community building
Installing MOSS on WinServer 2008 with Hyper-V and SQL08
Keeping up with SP Blogs
Use Search as Content Roll-up
Web browser compatibility in InfoPath Forms Services
Picture Library: Getting to the Thumbnails
All about dates and SPD
Data View Web Part, learn it... love it!
MSFT's SharePoint 2007 Buzz Kit
Content Query Web Part (CQWP) for All List Types
Content Query Web Part (CQWP) with Anonymous Access
My Blog is Live
Examples of Common Formulas
Creating a Form to Add Items to a SharePoint List
Building a Blog Host
Scaling to Extremely Large Lists
Configuring Email Alert Templates
Populating Form Data from SharePoint List Views
SharePoint Designer Workflows and InfoPath Form Libraries
Restoring the Quick Launch Bar in Web Part Pages
Creating a Hyperlink to an InfoPath Form
Changes to SPD Created Workflows
How to find the CSS Class Applied to any SharePoint Element
Publishing an InfoPath 2007 Form Template to a Server Running InfoPath Forms Services
Why you Shouldn't Choose "Enable Rendering on a Mobile Device" when Publishing an InfoPath Form Template
Find Form Template for an Existing Library
Adding a Portal Breadcrumb to your My Site
Define Custom Permission Levels
Exchange 2003 Hotfix (Outlook 2007 and SP Alerts)
Copyright© 1997-2009 Mike Geyer
The posts on this weblog are provided “AS IS” with no warranties, and confer no rights. The opinions expressed herein are personal.