Visual Studio Automation and Extensibility Reference
ProjectItems.AddFromTemplate Method

Creates a new project item from an existing item template file and adds it to the project.

Namespace: EnvDTE
Assembly: EnvDTE (in envdte.dll)

Syntax

Visual Basic (Declaration)
Function AddFromTemplate ( _
    <InAttribute> FileName As String, _
    <InAttribute> Name As String _
) As ProjectItem
Visual Basic (Usage)
Dim instance As ProjectItems
Dim FileName As String
Dim Name As String
Dim returnValue As ProjectItem

returnValue = instance.AddFromTemplate(FileName, Name)
C#
ProjectItem AddFromTemplate (
    [InAttribute] string FileName,
    [InAttribute] string Name
)
C++
ProjectItem^ AddFromTemplate (
    [InAttribute] String^ FileName, 
    [InAttribute] String^ Name
)
J#
ProjectItem AddFromTemplate (
    /** @attribute InAttribute() */ String FileName, 
    /** @attribute InAttribute() */ String Name
)
JScript
function AddFromTemplate (
    FileName : String, 
    Name : String
) : ProjectItem

Parameters

FileName

Required. The full path and file name of the template project file.

Name

Required. The file name to use for the new project item.

Return Value

A ProjectItem object.
Remarks

When you call AddFromTemplate, there is no need to explicitly create a new solution (such as with DTE.Solution.Create), because AddFromTemplate automatically creates a solution.

See Also

Tags :


Community Content

Ed Dore
AddFromTemplate always returns a NULL value

At one time, this was true. But with later versions of Visual Studio, which included the ability to add multiple items from a single template, the return value for this method could not return multiple items. So it now returns a NULL value in all instances. This is due to the contraint that the COM signature for this particular method cannot be changed without breaking a lot of code already in use.

Consequently, if you need the ProjectItem interface of the item just added via the AddFromTemplate call, you can either iterate through the ProjectItems collection, or you can create a ProjectItemsEvents.ItemAdded event just before calling AddFromTemplate, and store away the ProjectItem passed to your OnItemAdded handler.

Tags :

Page view tracker