How to: Access Application Data
The InfoPath managed code 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, which is instantiated by using the Application class.
In an InfoPath managed code form template project created using Visual Studio 2012, you can use the this (C#) or Me (Visual Basic) keyword to access an instance of the Application class that represents the current InfoPath application, which can then be used to access the properties and methods of the Application class.
Displaying the Application Name, Version, and Language ID
In the following example, the Name and Version properties of the Application class are used to return the name and version number of the running instance of InfoPath. The LanguageSettings property is then used to return a LanguageSettings object, which in turn is used to return the LCID (a four-digit number) for the language that is currently being used for the InfoPath user interface language. Finally, all of this information is displayed in a message box.
For the LanguageSettings property to work, you must establish a reference to the Microsoft Office 14.0 Object Library from the COM tab of the Add Reference dialog box in Visual Studio 2012. This will establish a reference to the Microsoft.Office.Core namespace, which contains the LanguageSettings class. Additionally, the form must be running as Full Trust.
This example requires a using or Imports directive for the Microsoft.Office.Core namespace in the declarations section of the form code module.
string appName = this.Application.Name; string appVersion = this.Application.Version; LanguageSettings langSettings = (LanguageSettings)this.Application.LanguageSettings; int langID = langSettings.get_LanguageID(MsoAppLanaguageID.msoLanguageIDUI); MessageBox.Show( "Name: " + appName + System.Environment.NewLine + "Version: " + appVersion + System.Environment.NewLine + "Language ID: " + langID);