Why is it that I can’t use a relative path for IO.StreamReader("Resources/file.txt")?
I’m working with a web app, so obviously the file isn’t going to be in the same absolute location between my development machine and the server.
How can I fix my filename path so it finds the file?
For reference, I have a file (relative to the page calling it) at path “Resources/file.txt” but the stupid function is looking in root “C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE.” And just in case it matters, I’m on .NET 3.5 at the moment.
Thanks. 🙂
Use HttpContext.Current.Server.MapPath(filename) to find the relative path to your file as a string then pass this to IO.StreamReader like so: