2

I have used Directory.getCurrentDirectory();

its giving only C:\Windows\SysWOW64

but i need to get the visual studio default project folder how can i get that ?

ex:C:\Users\knallasi\Documents\Visual Studio 2010\Projects\SampleApp

how do we find that above project location ?

Thanks in Advance

nallskarthi
  • 281
  • 1
  • 8
  • 19

2 Answers2

5

I'm not sure about the PROJECT directory, but the directory of the executing assembly can be found by using

string currentAssemblyDirectoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

usually, if you're executing in Visual Studio, the project directory is up two levels, you you could trim "bin\release| or "bin\debug" of that string to get the project directory, but that's a bit of a hack. I'm not sure there is a way to get the project directory from code.

David
  • 72,686
  • 18
  • 132
  • 173
1

After lots of searching I found the "dirty hack" solution for accessing things like $(ProjectDir) from within your code.

What's an easy way to access prebuild macros such as $(SolutionDir) and $(DevEnvDir) from code in C#?

Community
  • 1
  • 1
Jake
  • 4,829
  • 2
  • 33
  • 44