Home > Code Samples > How to add a file to a particular project

How to add a file to a particular project

October 22nd, 2010

Note, this article has been moved to the official DevExpress Support Center site. Please refer to the moved article as it might have further updates or additional comments. Thank you.

To programmatically add a file to a specific project, you can use the AddFileToProject method from the DXCore Solution service. Here is its definition:

public void AddFileToProject(string projectName, string filePath)

This method adds the specified file to the project with the given name. The project must be open in Visual Studio and be part of the active solution.

Parameters of the method:


The name of the project to add to.


The path of the file to add.

Consider the following solution structure:

DXCore Solution Explorer structure sample

In this case, you will add the Class2.cs file into the ClassLibrary1 project. Here’s a call to add a file:

CodeRush.Solution.AddFileToProject(“ClassLibrary1”, @“c:\MyFiles\CSFiles\Class2.cs”);

After that, you will see that the new file is added into the project:

DXCore Solution Explorer new file added

To add a file that depends on another file, see the corresponding topic.

Products: DXCore
Versions: 12.1 and up
VS IDEs: any
Updated: Oct/31/2012
ID: D027

Similar Posts: