0

The EnvDTE80.SolutionFolder interface (https://learn.microsoft.com/en-us/dotnet/api/envdte80.solutionfolder) has an AddFromFile() method, but requires the absolute full path of an existing file. Unfortunately the solution folder object itself doesn't contain a property with the path of the folder on disk.

Is there an easy way to create a new (text) file in a SolutionFolder without needing to know it's full absolute path? We just want a new file which is a direct child of the folder.

Something like this:

EnvDTE80.SolutionFolder folder;
var file = folder.CreateFile("myFile.txt");

But not:

EnvDTE80.SolutionFolder folder;
var file = folder.AddFromFile("c:\path_to_folder\myFile.txt");
TWT
  • 2,511
  • 1
  • 23
  • 37

1 Answers1

0

Unfortunately the solution folder object itself doesn't contain a property with the path of the folder on disk.

Exactly. It's because the solution folders are virtual, they are not related to any physical folders in the file system. You can have "MyFolder" solution folder in your solution and no "MyFolder" in you file system.

You CAN have also the physical folder just for the convenience:

C:\Solution
   MyFolder
      myFile.txt

But even then, this physical folder is absolutely unrelated to the solution folder. The solution folder may contain files from anywhere, even from outside the solution root physical folder. That's why you must supply the full path if you want to add a file to a solution folder.

If you know that you have the structure of solution folders mirrored also in physical folder structure, you can construct the full path manually. Get the directory name of the solution with EnvDTE80.Solution.FullName, combine it with the EnvDTE80.SolutionFolder.Parent.Name and then with the file name.

Peter Macej
  • 4,831
  • 22
  • 49