1

I have a text file in the application project classpath Directory of Windows Form Application. Now at the time of installation I am trying to write a text value into the text file. Here is my Installer class code for text file..

File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"\" + "ConnectionString.txt",param3);

After installation I want to retrieve the text that is entered in the "ConnectionString.txt" file and use it in the application but I am not getting how to retrieve the text value present in the text file.

rene
  • 41,474
  • 78
  • 114
  • 152
Adi
  • 1,395
  • 11
  • 37
  • 61
  • 2
    Unlike forum sites, we don't use "Thanks", or "Any help appreciated", or signatures on [so]. See [Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts). – rene Jan 02 '14 at 14:10

1 Answers1

5

try the following code snippet

Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ConnectionString.txt")

Read Text File

string result = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ConnectionString.txt"));
santosh singh
  • 27,666
  • 26
  • 83
  • 129
  • You can completely leave out the path here - it is relative to the calling assembly location anyway. – Thomas Weller Dec 21 '13 at 09:24
  • @geek Sir i am getting this error "System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\vikas\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\TechSoft CallBill\TechSoft CallBill.exe\ConnectionString.txt'." – Adi Dec 21 '13 at 09:29