Vault Application Framework code snippets for Visual Studio

See Installing using the Visual Studio Template Package.

Visual Studio Code Snippets are small blocks of reusable code that can be inserted into a code file using a context menu or set of key-presses. Code Snippets can be used to quickly create commonly-used code structures such as methods or properties, reducing the amount of code that developers must type to do so.

Code Snippets consist of a block of standardised text, and small editable sections. When a snippet is first entered, the editable sections are highlighted and the user can overtype the values to customise the code snippet. The developer can move between the editable elements of the snippet by pressing Tab, and press Enter or Esc to finish editing.

An example of a code snippet in 'Edit' mode

Executing Code Snippets

Using the keyboard

To execute a Code Snippet, the developer types the name of the code snippet (e.g. prop) and presses Tab twice. Visual Studio then executes the snippet and places it at the current location.

Inserting a code snippet using the keyboard

Resharper can alter the standard keyboard shortcuts. If you are using Resharper then You must press Ctrl-J, then type the code snippet name. The other keyboard shortcuts still work.

Using the mouse

To execute the code snippet, the developer right-clicks at the appropriate place in the code file and selects Insert Code Snippet.... The available code snippets are listed in a folder-style structure. The developer can double-click on the required Code Snippet and fill out the editable elements of the snippet by pressing Tab.

Inserting a code snippet using the mouse

Code Snippets and the Vault Application Framework

When developing applications using the Vault Application Framework it is common to create methods that are executed in response to various events within the vault, such as an object reaching a state in a workflow, or a property value requiring validation. Attributes are used to ensure that the Vault Application Framework knows which methods need to be executed at what time. These attributes often require the following method to have a specific signature in order to function; if the method does not match the expected signature then it will not be invoked.

The Vault Application Framework Attributes page details the attributes and their expected method signature, if appropriate.

Code Snippets can be used to automatically generate class members (methods and properties) with the correct structure and signatures, reducing development time.

Contributing to the Code Snippets

To contribute additional code snippets or to fix issues with existing code snippets, please visit the GitHub Samples and Libraries repository, fork the repository, make the required changes, then submit a pull request. GitHub has further information on forking and pull requests.

Available Code Snippets

See Installing using the Visual Studio Template Package.

The following code snippets exist. Once the snippets are installed, simply type their name within a code file, select the snippet, and press Tab twice.


Vault Extension Methods


Event Handlers

Vault Structural Elements (MFIdentifiers)


Installing the Vault Application Framework Code Snippets

Installing using the Visual Studio Template Package

Code Snippets are included in the M-Files Online Visual Studio Template Package. Installing this package also installs the code snippets listed here.

The package can be uninstalled by opening Visual Studio, clicking Tools, then Extensions and Updates..., as with other installed extensions.

The raw snippet files are available for download within our GitHub Samples and Libraries repository. To install the snippets manually: