views:

48

answers:

2

I know that in the same directory where my code is being executed some files are located. I need to find them and pass to another method:

MyLib.dll
Target1.dll
Target2.dll

Foo(new[] { "..\\..\\Target1.dll", "..\\..\\Target2.dll" });

So I call System.IO.Directory.GetFiles(path, "*.dll"). But now I need to get know the path:

string path = new FileInfo((Assembly.GetExecutingAssembly().Location)).Directory.FullName)

but is there more short way?

+3  A: 

You may try the Environment.CurrentDirectory property. Note that depending on the type of application (Console, WinForms, ASP.NET, Windows Service, ...) and the way it is run this might behave differently.

Darin Dimitrov
I'm running NUnit test. In real world I call `Foo(Server.MapPath("~/bin"))` but in test I just want to scan the root directory of the assembly containing the test
abatishchev
Thanks! `Environment.CurrentDirectory` is what I was looking for. My call returns something from Temp but your - exactly what I need.
abatishchev
+1  A: 

This post should give you a few options

mhenrixon