Using Relative URLs with the ServerInfo Class in InfoPath 2010

Hi, my name is Jill Anderson and I am a tester on the InfoPath team. In this post, I would like to introduce you to the one of the newest members of the InfoPath Object Model, the "ServerInfo" class.  For InfoPath forms published to a SharePoint server, the members of this class give you context about that particular site. Documentation about this new class can be found at:

In this short video demo, I show you how you can use the members of this class to enable your form to submit data using a relative URL.  This enables you to package a Site Collection as a WSP and move it to a new server.  With these changes, the submit data connection moves to the new server as well.

Initial Setup:

To make sure that my form template was correctly associated with my SharePoint Form Library both before and after the Site Collection Migration, I published it as a Content Type ( ). The ability to publish a Sandboxed Solution as a Content Type is a new feature for Office 2010.

Afterwards, I associated this content type with the correct SharePoint Form Library on the SharePoint Server. The steps to do this are as follows: 

  1. Create a new "Form Library"
  2. Open the newly created "Form Library"
  3. Open the "Library Settings" located under the "Library" Tab on the Ribbon
  4. Open "Advanced Settings" and set "Allow management of content types?" to "yes".
  5. Under "Content Types" select "Add from existing content types"
  6. Add the content type you published to the SharePoint server.

Sample Code:

This is the code I used to relativize the submit to the SharePoint site.

 /// <summary>
        /// Submits the form to the SubmittedTimeCards form library on SharePoint and calls a function to update the Vacation 
        /// and Sick Balance for the employee.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">Provides data for the Microsoft.Office.InfoPath.FormEvents.Loading event.</param>
        public void FormEvents_Submit(object sender, SubmitEventArgs e)
            FileSubmitConnection fileSubmit = (FileSubmitConnection)this.DataConnections["SharePoint Library Submit"];
            // Refreshing the Total number of hours and total pay for this given form.
            // Update the new Sick leave and Vacation Balance.
            // Relative the SharePoint Submit location to current SharePoint site.
            fileSubmit.FolderUrl = this.ServerInfo.SharePointSiteUrl.ToString() + "SubmittedTimeCards/";
            // If the submit operation is successful, set
            e.CancelableArgs.Cancel = false;

Additional Links

For more information about creating and publishing Sandboxed Solutions see Phil Newman's post on
Introduction to Sandboxed Solutions - Sort data in repeating tables using managed code