C# console application – file location

public void PrintFile()
{
	string helpFile = "test.txt"; // located in root 
	string WorkingDirectory = System.IO.Directory.GetCurrentDirectory().Replace("bin\\Debug", string.Empty); // replace string.Empty with subdirectory name if needed

	string file = string.Format("{0}\\{1}", WorkingDirectory, helpFile);
	using (System.IO.StreamReader r = new System.IO.StreamReader(System.IO.File.OpenRead(file)))
	{
		while (r.Peek() > -1)
		{
			Console.WriteLine(r.ReadLine());
		}
		Console.WriteLine();
	}
}

Leave a Reply

Your email address will not be published. Required fields are marked *