Click to Rate and Give Feedback

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
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)

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.

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.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
AddFromTemplate always returns a NULL value      Ed Dore   |   Edit   |   Show History

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 What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker