2

I have a c# project in this folder c:/devel/myapplication and in this c# solution i have a project which is a console application - c:/devel/myapplication/consoleapplication. In this folder I have some XML files which I want to read programmatically. How do I find the folder for the console application?

 var currentPath = Path.Combine(Path.GetDirectoryName(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName), myXmlPath);

This returns the root folder of my project/solution - I want the console projects folder.

Directory.GetCurrentDirectory()

returns bin/debug, which is also wrong

Any ideas?

jacob
  • 541
  • 1
  • 9
  • 19
  • 2
    My only question is: why? Can't you just make a build action to copy them? This scenario won't work when you run it outside the debug folder. – Patrick Hofman Sep 16 '14 at 13:55
  • http://stackoverflow.com/questions/21726088/how-to-get-current-working-directory-path-c – Chuck Buford Sep 16 '14 at 13:58
  • You probably want to add the XML files to your project and set them as "content", and "copy if newer". That will automatically copy them to where the program's exe is created. – George Duckett Sep 16 '14 at 14:02

2 Answers2

3
var parent = Directory.GetParent(Application.StartupPath);
Sefa
  • 8,865
  • 10
  • 51
  • 82
0
var currentPath = Path.Combine(Path.GetDirectoryName((Directory.GetCurrentDirectory())), myXmlPath);
Godspark
  • 354
  • 2
  • 13
  • Please do not post code only in your answer. Also include an explanation of what it is you have written and how it is relevant to answering the question. – arco444 Sep 16 '14 at 14:49