I am a beginner in C#, and I have a folder from which I am reading a file.
I want to read a file which is located at the parent folder of the solution file. How do I do this?
string path = "";
StreamReader sr = new StreamReader(path);
So if my file XXX.sln
is in C:\X0\A\XXX\
then read the .txt
files in C:\X0\A\
.
Try this:
string startupPath = Path.Combine(Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName,"abc.txt");
// Read the file as one string.
string text = System.IO.File.ReadAllText(startupPath);