Export (0) Print
Expand All

Publishing InfoPath 2007 Form Templates to Servers Running InfoPath Forms Services

Office 2007

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

Summary: Learn how to use Microsoft Visual Studio 2005 Tools for Applications to add managed code to a Microsoft Office InfoPath 2007 form template, publish it to a network share, and upload it to InfoPath Forms Services.

Office Visual How To

Applies to: Microsoft Office InfoPath 2007, Microsoft Office SharePoint Server 2007

David Gerhardt, 3Sharp

August 2007

Overview

With the InfoPath Forms Services capabilities in Microsoft Office SharePoint Server 2007, you can develop Microsoft Office InfoPath 2007 solutions that extend beyond the corporate firewall, delivering forms for Web browsers or even mobile devices. In browser scenarios, your forms can contain most of the rich functionality that is available in InfoPath 2007, and the publishing process for these forms is very easy.

Code It

Whether or not you use managed code in your form template, the publishing process starts with the InfoPath Publishing Wizard. For this scenario, you use the travel request sample that is included with Office InfoPath 2007, add a few lines of managed code to calculate a trip duration, and then publish the form template to InfoPath Forms Services.

Adding a Duration Node

Start the travel request sample template in the InfoPath designer, and follow these steps to add a Duration node.

To add a Duration node to the form view

  1. In the Design Tasks task pane, click Data Source.

  2. In the Data Source task pane, expand the trips node.

  3. Right-click the trips node, and then click Add.

  4. In the Add Field or Group dialog box, in the Name box, type Duration, and then click OK.

    Next, update the form view to include an expression box that is bound to the Duration node.

  5. In the form view, in the TRIP section, place the cursor to the right of the text Round trip and press SPACE three times.

  6. Drag the Duration node from the Data Source task pane to the right of the space characters you just added to the form view.

  7. Right-click the Duration text box, click Change To, and then click Expression Box.

  8. Reduce the size of the Duration expression box so that it appears on the same line as the corresponding heading, as shown in Figure 1.

    Figure 1. Adding Duration to the form view

    Adding Duration to the form view
NoteNote
You must save the form template locally before you add any code.

Including a Calculation Private Function

To add managed code to your form solutions, you can use Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office system (VSTO 2005 SE) or Microsoft Visual Studio 2005 Tools for Applications (VSTA). Office InfoPath 2007 includes Visual Studio 2005 Tools for Applications, which you use in this scenario to add a private function that calculates the total number of days in a given period.

NoteNote
You can set the programming language to Visual Basic or Visual C# before you add managed code to your form template. To do this, on the Tools menu, click Form Options, click the Programming category, and set the Form template code language list value accordingly.

To include a calculation function

  1. On the Tools menu, click Programming, and then click Microsoft Visual Studio Tools for Applications.

  2. In the FormCode class, add the following code.

    private string GetDuration(string startDate, string endDate)
    {
        string retValue;
        long longStartDate = DateTime.Parse(startDate).ToFileTimeUtc();
        long longEndDate = DateTime.Parse(endDate).ToFileTimeUtc();
        long longDayCount = (longEndDate - longStartDate) / 864000000000 + 1;
        retValue = longDayCount.ToString();
        return retValue;
    }
    

In the GetDuration function, the longDayCount long type identifies the difference in ticks between two date values divided by 864000000000 (the constant number of ticks in a day) plus 1. The result is the duration in days for the two date values and becomes the return value for the function.

Adding the Changed Events

The Duration expression box is meant to be updated with a new calculated value each time the departure date or return date is changed. Therefore, you add a Changed event for the Departure Date and Return Date date picker controls.

To add Changed events

  1. Right-click the Departure Date date picker control, click Programming, and then click Changed Event.

  2. In VSTA, in the departureDate_Changed procedure, add the following code.

    string departDate = e.Site.InnerXml;
    string returnDate = e.Site.SelectSingleNode("../my:roundTrip/my:returnDate", NamespaceManager).InnerXml;
    if (departDate != string.Empty && returnDate != string.Empty)
    {
        e.Site.SelectSingleNode("../my:Duration", NamespaceManager).SetValue(GetDuration(departDate, returnDate));
    }
    else
    {
        e.Site.SelectSingleNode("../my:Duration", NamespaceManager).SetValue("NA");
    }
    

    Next, you return to the InfoPath designer and add a Changed event for the Return Date date picker control.

  3. Right-click the Return Date date picker control, click Programming, and then click Changed Event.

  4. In VSTA, in the returnDate_Changed procedure, add the following code, which is slightly different from the code you added to the departureDate_Changed procedure.

    string departDate = e.Site.SelectSingleNode("../../my:departureDate", NamespaceManager).InnerXml;
    string returnDate = e.Site.InnerXml;
    if (departDate != string.Empty && returnDate != string.Empty)
    {
        e.Site.SelectSingleNode("../../my:Duration", NamespaceManager).SetValue(GetDuration(departDate, returnDate));
    }
    else
    {
        e.Site.SelectSingleNode("../../my:Duration", NamespaceManager).SetValue("NA");
    }
    

Each Changed event makes a call to the GetDuration procedure and sets the Duration node accordingly.

Updating Postback Options

Before the form template is deployed, you must update the two date picker controls to ensure that data is sent to the server each time the departure date or return date is changed.

To update the date picker controls

  1. Close VSTA, and in InfoPath, double-click the Departure Date date picker control.

  2. In the Date Picker Properties dialog box, click the Browser forms tab.

  3. Click Always, and then click OK.

  4. Repeat the previous three steps for the Return Date date picker control.

  5. Press CTRL+S to save the form template.

Deploying the Form Template

Because the form template uses managed code for a browser scenario, it must be admin-deployed. In other words, you must first publish the form template to a network share.

NoteNote
If a form template does not contain managed code, you can publish it directly to a SharePoint site.

To publish a form template to a network share

  1. On the File menu, click Publish.

  2. On the first page of the Publishing Wizard, click To a SharePoint server with or without InfoPath Forms Services, and then click Next.

  3. On the next page, in the Enter the location of your SharePoint or InfoPath Forms Services site box, type the URL for the SharePoint site, and then click Next.

  4. On the next page, note that the Administrator-approved form template option is selected, and click Next.

  5. On the next page, click Browse, and browse to a network share location.

  6. In the File name box, type TravelRequest, click Save, and then click Next.

  7. On the next page, note the promoted columns, and click Next.

  8. On the next page, click Publish.

  9. On the last page of the Publishing Wizard, click Close.

After the form template is published to a network share, a server administrator can upload that form template to InfoPath Forms Services and activate it to a specific Windows SharePoint Services 3.0 site collection.

To upload a form template to InfoPath Forms Services

  1. Click Start, click All Programs, click Microsoft Office Server, and then click SharePoint 3.0 Central Administration.

  2. On the Central Administration page, click Application Management.

  3. In the InfoPath Forms Services section, click Manage form templates.

  4. On the Manage Form Templates page, click Upload form template.

  5. Click Browse, locate TravelRequest.xsn, and double-click it.

  6. Click Upload, and then click OK.

    NoteNote
    Wait until the Status value for TravelRequest.xsn changes from Installing to Ready.
  7. On the TravelRequest.xsn menu, click Activate to a Site Collection.

  8. Update the Site Collection list value accordingly, and then click OK.

Starting the Travel Request Form

To test your changes, start the travel request form template in the browser and modify the Departure Date and Return Date fields.

To modify the Departure Date and Return Date fields

  1. In Microsoft Internet Explorer, navigate to the browser location of your form template, which will be http://Your_Web_Application_URL/_layouts/formserver.aspx?xsnlocation=/formservertemplates/travelrequest.xsn&openin=browser.

    NoteNote
    The travel request template has a rule, executed when the form starts, that sets the Departure Date to today and the Return Date to three days from today.
  2. Select the Round trip check box.

  3. Change the Return Date to tomorrow.

  4. Change the Departure Date to yesterday.

Read It

InfoPath 2007 enables you to develop form templates that can run in InfoPath Forms Services, thus allowing them to be accessed from a Web browser. With Visual Studio Tools for Applications, you can use the InfoPath event framework to easily add managed code to these form templates. To admin-deploy these form templates:

  • Use the InfoPath Publishing Wizard to save the form template to a network share.

  • Have a server administrator upload that form template to InfoPath Forms Services and then activate it to a specific site collection.

See It

Publishing Form Templates

Watch the Video

Video Length: 00:09:33

File Size: 9.08 MB WMV

Explore It
Show:
© 2014 Microsoft