AddFromFile Method (ProjectItems Collection)
Adds a project item from a file that is installed in a project directory structure.
Public Function AddFromFile( _ ByVal FileName As String _ ) As ProjectItem
Function AddFromFile( _ ByVal FileName As String _ ) As ProjectItem
HRESULT __stdcall AddFromFile( BSTR FileName, /* [out, retval] */ ProjectItem** retVal );
ProjectItem AddFromFile( string FileName );
public function AddFromFile( FileName : String ) : ProjectItem
- Required. The file name of the item to add as a project item.
Returns a ProjectItem object.
This method should fail if the file to be added is already in the project.
FileName does not necessarily have to contain a full path as long as the file can be found. How a file is found depends upon the programming language. In order to use pathless files in Visual Basic .NET and Visual C# .NET, for example, the files must be in the same directory as the project. If they are not, they are copied over. Visual C++ .NET allows linking to files anywhere on the system.
The following example is designed to be run in Macros IDE. Before running this example, create a file named "An Item.bas" in the path C:\temp.
Sub AddFromFileExample() ' This function creates a solution and adds a Visual Basic .NET Console ' project to it. Dim soln As Solution Dim proj As Project Dim projitems As ProjectItems ' Create a reference to the solution. soln = DTE.Solution ' Create a new solution. soln.Create("c:\temp2", "MyNewSolution") ' Create a new VB Console application project. Adjust the save path as ' needed. proj = soln.AddFromTemplate("C:\Program Files\Microsoft Visual Studio .NET\Vb7\VBWizards\ConsoleApplication\Templates\1033\ConsoleApplication.vbproj", "c:\temp2", "My New Project", True) projitems = proj.ProjectItems ' Add a project item from a file. projitems.AddFromFile("C:\temp\An Item.bas") End Sub
Applies To: ProjectItems Collection