How to access a text file in Windows Form Application
c#, file-handling, io, windows, windows-forms-designer
Solution
Use this:
string s = Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"Licence.txt");
Do not try to combine paths manually because you must deal with path delimiters... using builtin functions is much better!
Finally remember to set `Copy to Output` property on License.txt file inside your project.
Problem
I have added a text file into Windows form Application and trying to access this file. Here is my code.. ``` static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); System.String s = Application.StartupPath+"/Licence.txt"; System.IO.FileInfo fi = new System.IO.FileInfo(s); if (fi.Exists) { if (fi.Length == 0) { Application.Run(new Form1()); } } } ``` Licence.txt is there in my project folder but every time (fi.Exists) comes to be false only and program comes out of the flow without showing Form1() window.. Please Help me. Thanks in advance..