I am new to C#. Created a C# application which reads from a file and does some processing. I have manually put the files under myProject/bin/Debug/files/
(Note: manually copy-pasted file, not sure if i need to import in any way through the application - using SharpDevelop IDE). My code reads the file through
string query = File.ReadAllText(@"files\myfile.txt");
After I built and passed it to a client and it's working fine when they click on myproject.exe
, it can locate the file. But when they trigger it using windows task scheduler, the error they get is:
System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Windows\system\files\myfile.txt'... at extractor.Program.query() in d:\workspace\test\Program.cs:line 81 (this is my local path, shoud show client's folder path instead)
Need help with:
myfile.txt
as necessary, without touching the .exe (without the need to build again)@"files\myfile.txt"
).Appreciate help.
use like this
string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
String query = File.ReadAllText(Path.Combine(path, "files\\Test.txt"));