Path to resource files in a VS2010 project

早过忘川 提交于 2019-12-24 07:57:24

问题


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.



来源:https://stackoverflow.com/questions/12212456/path-to-resource-files-in-a-vs2010-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!