XmlFormCollection.NewFromFormTemplate method (String, XPathNavigator)

Creates a new form by using the specified form template with data specified by an XPathNavigator object.

Namespace:  Microsoft.Office.InfoPath
Assembly:  Microsoft.Office.InfoPath (in Microsoft.Office.InfoPath.dll)

Syntax

'Declaration
Public MustOverride Function NewFromFormTemplate ( _
    formTemplateLocation As String, _
    xmlData As XPathNavigator _
) As XmlForm
'Usage
Dim instance As XmlFormCollection
Dim formTemplateLocation As String
Dim xmlData As XPathNavigator
Dim returnValue As XmlForm

returnValue = instance.NewFromFormTemplate(formTemplateLocation, _
    xmlData)
public abstract XmlForm NewFromFormTemplate(
    string formTemplateLocation,
    XPathNavigator xmlData
)

Parameters

  • formTemplateLocation
    Type: System.String

    The Uniform Resource Identifier (URI) of the form template on which to base the new form.

Return value

Type: Microsoft.Office.InfoPath.XmlForm
An XmlForm object that represents the new form that was created.

Exceptions

Exception Condition
ArgumentException

The parameter that was passed to this method is not valid. For example, it is of the wrong type or format.

ArgumentNullException

The parameter that was passed to this method is a null reference (Nothing in Visual Basic).

FileNotFoundException

The file specified for formTemplateLocation does not exist.

InvalidOperationException

This method was called from an event handler for the Loading event.

Remarks

The NewFromFormTemplate method can only be used to create a new form that is based on an existing form template; it cannot be used to create a new form that is based on a form. To create a form from an existing form, use the New method.

When you use the NewFromFormTemplate method, the new form opens in InfoPath and is ready to be filled out.

This member can be accessed only by forms running in the same domain as the currently open form, or by forms that have been granted cross-domain permissions.

This type or member can be accessed only from code running in forms opened in Microsoft InfoPath Filler.

Examples

In the following code example, the NewFromFormTemplate(formTemplateLocation, xmlData) method of the XmlFormCollection class is passed the URI of an existing form template and an XPathNavigator object that returns XML data, and the new form's associated XmlForm object returned.

// Create an in-memory XML document.
XmlDocument newDoc = new XmlDocument();
// Load the document with some XML.
newDoc.LoadXml(
   "<?xml version=\"1.0\" encoding=\"utf-8\" ?><person><firstName/><lastName/><address/><city/><country/></person>");
// Create an XPathNavigator for the XML file.
XPathNavigator newDocNav = newDoc.CreateNavigator();
// Call NewFromFormTemplate to open new form and load XML.
XmlForm newDocument = 
   this.Application.XmlForms.NewFromFormTemplate(
   @"C:\MyForm.xsn", newDocNav);
' Create an in-memory XML document.
Dim newDoc As XmlDocument = new XmlDocument()
' Create XML to load.
Dim xmlToLoad As String = "<?xml version=" & Quote & "1.0" & Quote & _
   " encoding=" & Quote & "utf-8" & Quote & _
   " ?><person><firstName/><lastName/><address/>" & _
   "<city/><country/></person>"
' Load the document with some XML.
newDoc.LoadXml(
   )
' Create an XPathNavigator for the XML file.
Dim newDocNav As XPathNavigator  = newDoc.CreateNavigator()

' Call NewFromFormTemplate to open new form and load XML.
Dim newDocument As XmlForm  = _
   Me.Application.XmlForms.NewFromFormTemplate(_
   "C:\MyForm.xsn", newDocNav)

See also

Reference

XmlFormCollection class

XmlFormCollection members

NewFromFormTemplate overload

Microsoft.Office.InfoPath namespace