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: http://msdn.microsoft.com/en-us/library/microsoft.office.infopath.serverinfo.aspx.
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.
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 (http://office.microsoft.com/en-us/infopath-help/create-a-sharepoint-library-or-site-content-type-for-your-form-template-HA010103005.aspx ). 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:
- Create a new "Form Library"
- Open the newly created "Form Library"
- Open the "Library Settings" located under the "Library" Tab on the Ribbon
- Open "Advanced Settings" and set "Allow management of content types?" to "yes".
- Under "Content Types" select "Add from existing content types"
- Add the content type you published to the SharePoint server.
This is the code I used to relativize the submit to the SharePoint site.
/// Submits the form to the SubmittedTimeCards form library on SharePoint and calls a function to update the Vacation
/// and Sick Balance for the employee.
/// <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;
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