Show All

# Accessing application data

The Microsoft Office InfoPath 2003 object model provides objects and collections that can be used to gain access to information about the InfoPath application, including information related to a form's underlying XML document and the form definition (.xsf) file. This data is accessed through the top-level object in the InfoPath object model hierarchy— the Application object.

Using the Application object, InfoPath form developers can access information about the currently installed instance of InfoPath, including its name and version number. In the following example, the Name and Version properties of the Application object return data in a message box to the user:

    Application.XDocuments(0).UI.Alert("Application name: " + Application.Name +
       "\nApplication version: " + Application.Version);

Note that the Alert method of the UI object, which is accessed through the XDocument object, is used to display a message box to the user. Because the XDocument object that represents the currently open form's underlying XML document is embedded in the InfoPath script engine, the previous example can also be written as follows:

    XDocument.UI.Alert("Application name: " + Application.Name +
       "\nApplication version: " + Application.Version);

Note The `\n` character references in the text for the alert message is a standard new line feed that causes the text to break and be placed on a new line in the message box.

Accessing data about a form's XML document

Developers can use the XDocument object to gain access to information about a form's underlying XML document, including a reference to an XML Document Object Model (DOM) that contains the source XML data of the form.

In the following example, the first message box displays some of the data that is available for the XDocument object, such as whether it has been changed (using the IsDirty property) and whether it has been digitally signed (using the IsSigned property). The next message box uses the XDocument object's DOM property to display the source XML of the form's underlying XML document.

    XDocument.UI.Alert("\nIsDirty: " + XDocument.IsDirty +
       "\nIsDOMReadOnly: " + XDocument.IsDOMReadOnly +
       "\nIsNew: " + XDocument.IsNew +
       "\nIsReadOnly: " + XDocument.IsReadOnly +
       "\nIsSigned: " + XDocument.IsSigned);

    XDocument.UI.Alert(XDocument.DOM.xml);

Note The xml property used in the previous example is a property of the XML DOM. For more information about the XML DOM, see the MSXML 5.0 SDK documentation in the Microsoft Script Editor (MSE) Help system.

Accessing data about a form's .xsf file

Information about a form's .xsf file, including an XML DOM reference to the source XML data that it contains, can also be accessed using the XDocument object. This information is accessed using the XDocument object's Solution property, which returns a reference to the Solution object.

In the following example, the first alert displays some of the data that is available for the Solution object, such as its Uniform Resource Identifier (URI) location (using the URI property) and its version number (using the Version property). The next alert uses the Solution object's DOM property to display the source XML of the .xsf file.

    XDocument.UI.Alert("PackageURL: " + XDocument.Solution.PackageURL +
       "\nURI: " + XDocument.Solution.URI +
       "\nVersion: " + XDocument.Solution.Version);

       XDocument.UI.Alert(XDocument.Solution.DOM.xml);

©2003-2004 Microsoft Corporation. All rights reserved. Permission to copy, display and distribute this document is available at: http://msdn.microsoft.com/library/en-us/odcXMLRef/html/odcXMLRefLegalNotice.asp