Freigeben über


VSProject.TemplatePath Property

Gets the full path of the directory that contains the project-item templates for Visual Basic or C#. Read-only.

Namespace:  VSLangProj
Assembly:  VSLangProj (in VSLangProj.dll)

Syntax

'Declaration
ReadOnly Property TemplatePath As String
string TemplatePath { get; }
property String^ TemplatePath {
    String^ get ();
}
abstract TemplatePath : string with get
function get TemplatePath () : String

Property Value

Type: String
Returns a string value representing the template path.

Remarks

This property returns the appropriate template directory path, depending on whether the project is a Visual Basic project or a C# project.

Custom project items, such as forms and modules, may be copied to the template path. These items may then serve as templates for new items. The AddFromTemplate method of the ProjectItems object creates a copy of the template in the project directory and adds the project item to the specified project. An example follows.

Examples

[Visual Basic]

' Macro Editor
' Uses the template path to add a copy of the 
' CompanyTemplate form to the project.
Imports VSLangProj
Sub TemplatePathExample()
   ' This example assumes that the first project in the solution is 
   ' either a Visual Basic or C# project.
   Dim aVSProject As VSProject = _
      CType(DTE.Solution.Projects.Item(1).Object, VSProject)
        
   ' Use the path to create a new project item.
   Dim aProject As Project = DTE.Solution.Projects.Item(1)
   Dim thePath As String = aVSProject.TemplatePath
   Dim formName As String = InputBox("Name of new form with extension:")
   Dim newItem As ProjectItem
   newItem = aProject.ProjectItems.AddFromTemplate(thePath & _
      "\CompanyTemplate.vb", formName)
End Sub

.NET Framework Security

See Also

Reference

VSProject Interface

VSLangProj Namespace