NewFromSolutionWithData Method

Microsoft Office InfoPath

Creates a new Microsoft Office InfoPath 2003 form using the specified XML data and form template.

expression. NewFromSolutionWithData(ByVal varXMLData As Variant, ByVal varSolutionURI As Variant, [ByVal dwBehavior As Long = 1]) As XDocument

expression    An expression that returns a reference to an XDocuments collection.

varXMLData    Required Variant. Provides the XML data to be used as a template for the form. Can be a string that specifies the Uniform Resource Identifier (URI) of an XML document, or an XMLDOMNode that contains the XML to be used as the XML document (template).

varSolutionURI    Required Variant. String which specifies the Uniform Resource Identifier (URI) of a form template file (an .xsf or .xsn file).

dwBehavior    Optional Long. Reserved for future use. This value should be omitted or set to 1.

returns    A reference to an XDocument object.

Security Level

2: 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.

Remarks

The following related methods of the XDocuments collection are also available:

  • The New method enables creating a new instance of InfoPath by using a specified XML document. The XML document must correspond to an InfoPath form. A new form is opened in InfoPath, using the supplied XML document as initial data, and its associated form template as specified in the processing instructions in the header of the document.

  • The NewFromSolution method enables creating a new instance of InfoPath using a specified form template, and its associated XML form (the initial template data).

The NewFromSolutionWithData method supports a scenario that is not provided by the foregoing two methods: specifying both the XML document used as initial data and the form template. The XML document does not need to have been created by InfoPath. It can be supplied either as a URI or as an XMLDOMNode.

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

Note  This object model member is not supported when the Disable Service Pack features option on the Advanced tab of the Options dialog box in InfoPath is selected or when Microsoft Office 2003 Service Pack 1 or later is not installed. Any form that implements this object model member in its code will generate an error message if it is opened in InfoPath when service pack features are disabled or unavailable.

Example

In the following example, the NewFromSolutionWithData method of the XDocuments collection is passed the URIs of an existing XML document, and an existing form template, and a new form is created and its associated XDocument object is returned:

var objXDoc = Application.XDocuments.NewFromSolutionWithData("C:\\InitialData.xml", "C:\\MyForm.xsn");

In the following example, the NewFromSolutionWithData method of the XDocuments collection is passed an XMLDOMNode as initial data and the URI of an existing form, and a new form is created and its associated XDocument object is returned:

var objXMLNode = XDocument.DOM.selectSingleNode("/employees/employee");

var objXDoc = Application.XDocuments.NewFromSolutionWithData(objXMLNode, "C:\\Employee.xsn");