Compartir a través de


ProjectItems.AddFromFile Method

Adds a project item from a file that is installed in a project directory structure.

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

Syntax

'Declaration
Function AddFromFile ( _
    FileName As String _
) As ProjectItem
ProjectItem AddFromFile(
    string FileName
)
ProjectItem^ AddFromFile(
    [InAttribute] String^ FileName
)
abstract AddFromFile : 
        FileName:string -> ProjectItem
function AddFromFile(
    FileName : String
) : ProjectItem

Parameters

  • FileName
    Type: System.String

    Required. The file name of the item to add as a project item.

Return Value

Type: EnvDTE.ProjectItem
A ProjectItem object.

Remarks

AddFromFile fails if the file to be added is already in the project.

FileName need not contain a full path as long as the file can be found. How a file is found depends on the programming language. In order to use pathless files in Visual Basic and Visual C#, for example, the files must be in the same directory as the project. If they are not, they are copied over. Visual C++ allows linking to files anywhere on the system.

Examples

Sub AddFromFileExample(app As DTE)
   ' This function creates a solution and adds a Visual Basic Console
   ' project to it. 
   Dim soln As Solution
   Dim proj As Project
   Dim projitems As ProjectItems

   ' Create a reference to the solution.
   soln = app.Solution

   ' Create a new solution.
   soln.Create("c:\temp2", "MyNewSolution")

   ' Create a new Visual Basic Console application project.
   ' Adjust the save path as needed.
   proj = soln.AddFromTemplate("C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ImportProjects\VB\ImportConsoleApplication.vbproj", "c:\temp2", "My New Project", True)
   projitems = proj.ProjectItems

   ' Add a project item from a file.
   projitems.AddFromFile("C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\NewFileItems\vbclass.vb")
End Sub

.NET Framework Security

See Also

Reference

ProjectItems Interface

EnvDTE Namespace

Other Resources

How to: Compile and Run the Automation Object Model Code Examples