Custom Software Apps & SharePoint Consulting

InfoPath 2007 In-Browser Filtering for SharePoint Server 2007

Microsoft Office SharePoint Server (MOSS) 2007 offers out-of-the-box web forms for data entry and maintenance with each list and library you create. These forms are sufficient for most tasks, but do not offer much in terms of intelligence nor do they offer the flexibility to infuse your own intelligence into the form. If you are looking for more out of your MOSS 2007 forms, you must create custom forms yourself.

There are two options available to build a custom form in MOSS 2007. First, you may write a custom ASP.net page and use SharePoint Designer 2007 (now available for free from Microsoft) to point to the page you create. Alternatively, you may use InfoPath 2007 (or InfoPath 2010, which imposes restrictions based on your target deployment environment).

If you choose InfoPath 2007, you will enjoy many built-in functions and wizards which make many of your construction and deployment tasks a breeze. InfoPath even allows you to build forms which can be displayed in a browser, eliminating the need to install the InfoPath application on the client systems! A great feature, until you discover its limitations, which brings us back to the topic of this blog.

One very common scenario is when a user is given a form to complete, and certain choices will change based on a previously selected choice.

For example, let’s use the make and model of a car. The list of models to choose from will change based on the make of car the user has selected. Here’s a brief summary of the steps necessary to build a custom in-browser filter:

1. If you do not have Visual Studio Tools for Applications installed, do so from Add/Change Programs in Control Panel

2. Open a new form template in InfoPath 2007 and add two drop-down list controls, call them Make and Model

3. Create a secondary data source for your Make/Model information

4. Create the “Changed” event for the parent control and paste this code in the event handler:

//Filter Models based on Make
public void txtMake_Changed(object sender, XmlEventArgs e)
{
//Get a hook to   our Main datasource
XPathNavigator root;
root = this.MainDataSource.CreateNavigator();
//Re-populate   data source
//  Filtered values are deleted from the   datasource so the list must be refreshed
this.DataConnections[“Car_Models”].Execute();
XPathNodeIterator vehicles =
this.DataSources[“Car_Models”].CreateNavigator().Select(“/Root/Vehicles/Vehicle”, this.NamespaceManager);
//Get user   selected Make value
String make = root.SelectSingleNode(“/my:MyFields/my:txtMake”, this.NamespaceManager).Value;
//Iterate   through each make, deleting all entries except the one we want
for (int i = vehicles.Count; i > 0; i–)
{
//Get a   make node and compare it to the user’s selection
//Delete if   not a match
XPathNavigator vehicle =
this.DataSources[“Car_Models”].CreateNavigator().SelectSingleNode(“/Root/Vehicles/Vehicle[” + i + “]“,    this.NamespaceManager);
if (vehicle.GetAttribute(“make” , String.Empty) != make)
{
vehicle.DeleteSelf();
}
}
}

5. Be sure to set the control’s Postback settings (under the “Browser Forms” tab in properties) to “Always” 6. Publish your form as a Farm Admin and test it out!

If you are clinging to your MOSS 2007 platform and reluctant to migrate to SharePoint 2010, this workaround may help you stave off the inevitable a little longer.

Share this post with your friends

Skip to content