How to read the text file from the Application Directory text file

久未见 提交于 2019-12-23 04:08:36

问题


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.


回答1:


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"));


来源:https://stackoverflow.com/questions/20717407/how-to-read-the-text-file-from-the-application-directory-text-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!