The CodeTemplateInfo Object

The CodeTemplateInfo object (available through the CodeTemplateInfo property of the CodeTemplate object) can be used to retrieve a variety of information about the current template:

Property

Returns

CodeBehind

Gets the full path to the code-behind file for the template (or an empty string if there is no code-behind file).

ContentHashCode

Gets the hash code based on the template content and all template dependencies.

DateCreated

Gets the date the template was created.

DateModified

Gets the date the template was modified.

Description

Gets the description.

DirectoryName

Gets the name of the directory the template is located in.

FileName

Gets the name of the template file.

FullPath

Gets the full path to the template.

Language

Gets the template language.

TargetLanguage

Gets the target language.

Here's a simple example of using the CodeTemplateInfo object:

<%@ CodeTemplate Language="VB" TargetLanguage="Text" Description="Demonstrates CodeTemplateInfo." %>
<% DumpInfo() %>
<script runat="template">
Public Sub DumpInfo()
Response.WriteLine("Template: {0}", Me.CodeTemplateInfo.FileName)
Response.WriteLine("Created: {0}", Me.CodeTemplateInfo.DateCreated)
Response.WriteLine("Description: {0}", Me.CodeTemplateInfo.Description)
Response.WriteLine("Location: {0}", Me.CodeTemplateInfo.FullPath)
Response.WriteLine("Language: {0}", Me.CodeTemplateInfo.Language)
Response.WriteLine("Target Language: {0}", Me.CodeTemplateInfo.TargetLanguage)
End Sub
</script>

The output of running this template will be similar to this:

Template: CodeTemplateInfo.cst
Created: 1/1/1973 8:54:19 AM
Description: Demonstrates CodeTemplateInfo.
Location: C:\CodeTemplateInfo.cst
Language: VB
Target Language: Text