2

I need to get the path like.

"C:\Projects\ProjectName\ConfigFiles\filename.txt"

It is for windows application.After installing this application i need to access "filename.txt" from the installed path.

I have tried many codes like

Assembly.GetExecutingAssembly().Location
System.IO.Directory.GetCurrentDirectory()
etc...

These all code returns "C:\Project\ProjectName\bin\Debug" path. Please help.

Thanks in advance.

Sajith A.K.
  • 716
  • 9
  • 21

2 Answers2

1

You can simply use this piece of code, assuming that you have a filename.txt placed inside directory ConfigFiles.

var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ConfigFiles", "filename.txt");
Furqan Safdar
  • 16,260
  • 13
  • 59
  • 93
-1

I think there is no build in way to get the installation path of your application. Your installer could write the path to the registry or an environment variable and your program could get it from there. In the case of an environment variable you gould use Environment.GetEnvironmentVariable

bernd_rausch
  • 335
  • 2
  • 9
  • Yuck, great way to make applications break when moved without reinstalling them. *Of course* an application can find out where it is located... – ThiefMaster Oct 08 '12 at 06:38
  • I don't think the question was to find the current directory of the application. I thought he wants to get the installation directory of the application, even when he start a debug version from within visual studio. – bernd_rausch Oct 08 '12 at 19:46