I want to open a txt file and read from it here's the code:
StreamReader reader = File.OpenText("TrackData/vehicle_points.txt");
TrckData
is a folder in my web application.
but i get this error :
Could not find a part of the path 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\TrackData\vehicle_points.txt'.
My project is not even in C Driver, I don't know where it gets that url.
ASP.Net applications are stored in a different folder, and here you have given a relative which may vary according to asp.net executable path.
Please use
string path = Server.MapPath("TrackData/vehicle_points.txt");
StreamReader reader = File.OpenText(path);
this will surely work..
File.OpenText
will start with the path being the current directory - this is the directory the executable is in.
You need to give it the correct full path to the file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With