Most of the examples shows how to read text file from exact location (f.e. \"C:\\Users\\Owner\\Documents\\test1.txt\"). But, how to read text files without writing full path
When you provide a path, it can be absolute/rooted, or relative. If you provide a relative path, it will be resolved by taking the working directory of the running process.
Example:
string text = File.ReadAllText("Some\\Path.txt"); // relative path
The above code has the same effect as the following:
string text = File.ReadAllText(
Path.Combine(Environment.CurrentDirectory, "Some\\Path.txt"));
If you have files that are always going to be in the same location relative to your application, just include a relative path to them, and they should resolve correctly on different computers.
If your application is a web service, Directory.CurrentDirectory
doesn't work.
Use System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "yourFileName.txt"))
instead.