VSProject.TemplatePath Property

Definition

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

public:
 property System::String ^ TemplatePath { System::String ^ get(); };
public:
 property Platform::String ^ TemplatePath { Platform::String ^ get(); };
[System.Runtime.InteropServices.DispId(8)]
public string TemplatePath { [System.Runtime.InteropServices.DispId(8)] get; }
[<System.Runtime.InteropServices.DispId(8)>]
[<get: System.Runtime.InteropServices.DispId(8)>]
member this.TemplatePath : string
Public ReadOnly Property TemplatePath As String

Property Value

Returns a string value representing the template path.

Attributes

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  

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.

Applies to