Share via


Application.RegisterFormTemplate Method (String, String)

Installs the specified form template with the option to overwrite the previous registration record for the form template.

Namespace: Microsoft.Office.InfoPath
Assembly: Microsoft.Office.InfoPath (in microsoft.office.infopath.dll)

Syntax

'Declaration
'Usage

Parameters

  • formTemplateLocation
    Specifies the Uniform Resource Locator (URL) of the form template. This parameter can be specified as a form definition (.xsf) file or a form template (.xsn) file.
  • behavior
    Specifies how the form template is to be installed. The default value is "overwrite". The only other valid value for this parameter is "new-only".

Exceptions

Exception type Condition

FileNotFoundException

The form template file cannot be found.

ArgumentNullException

The parameters passed to this method are null.

ArgumentException

The parameters passed to this method arenot valid. For example, they are of the wrong type or format.

Remarks

If the form template has already been registered, and "new-only" is specified for the behavior parameter, the RegisterFormTemplate method will return an error. If "overwrite" is specified, the form template's registration record will be overwritten.

This member can be accessed only by forms opened from a form template that as been configured to run with full trust using the Security and Trust category of the Form Options dialog box. This member requires full trust for the immediate caller and cannot be used by partially trusted code. For more information, see "Using Libraries from Partially Trusted Code" on MSDN.

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

Example

In the following example, the RegisterFormTemplate method of the Application class is used in a function to install a form template. The example assumes that there is a using or Imports statement for the Microsoft.Office.InfoPath namespace in the declarations section of the class that contains the function, and that the Microsoft InfoPath 2.0 Type Library is referenced on the COM tab of the Add Reference dialog box in Visual Studio.

public void InstallForm()
{
Microsoft.Office.InfoPath.Application infoPathApp = 
   new Microsoft.Office.InfoPath.Application();
infoPathApp.RegisterFormTemplate(@"C:\My Forms\MyFormTemplate.xsn", 
   "overwrite");
}
Public Sub InstallForm()
Dim infoPathApp As Microsoft.Office.InfoPath.Application = _
   new Microsoft.Office.InfoPath.Application()
infoPathApp.RegisterFormTemplate("C:\My Forms\MyFormTemplate.xsn", _
   "overwrite")
End Sub

.NET Framework Security

See Also

Reference

Application Class
Application Members
Microsoft.Office.InfoPath Namespace