1 out of 3 rated this helpful - Rate this topic

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)

ProjectItem AddFromTemplate (
	[InAttribute] string FileName,
	[InAttribute] string Name
)
ProjectItem AddFromTemplate (
	/** @attribute InAttribute() */ String FileName, 
	/** @attribute InAttribute() */ String Name
)
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.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
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.

Advertisement