Path to resource files in a VS2010 project

2019-07-28 19:23发布

问题:

I'm using VS 2010 and .NET 4.0.

I've created a solution, with a single console C# project. I've added a few folders in the project via context menu on project > Add > New folder. Then I put some files in there.

I now wish to get the path (or file handle) to one of those resources. Is there a nice way to getting its path?

NOTE 1: The project is on a source control, so I need a way that will work on different file paths.

NOTE 2: If possible, I don't want to use Directory.GetCurrentDirectory() nor System.Reflection.Assembly.GetExecutingAssembly().Location.

EDIT:

It seems, I'd like the direct answer to this Stackoverflow question. I want the project directory, without the "bin\Debug"

回答1:

From MSDN:

string path = System.IO.Path.GetDirectoryName( 
  System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase );

Also check this Stackoverflow answer.