Share via

ProjectItems.AddFromFile(String) Method


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

 EnvDTE::ProjectItem ^ AddFromFile(System::String ^ FileName);
 EnvDTE::ProjectItem ^ AddFromFile(Platform::String ^ FileName);
EnvDTE::ProjectItem AddFromFile(std::wstring const & FileName);
public EnvDTE.ProjectItem AddFromFile (string FileName);
abstract member AddFromFile : string -> EnvDTE.ProjectItem
Public Function AddFromFile (FileName As String) As ProjectItem



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


A ProjectItem object.



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  


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.

Applies to