In a class library, I have a file that is set to copy to output directory at NewFolder1/HTMLPage1.htm
.
I tried this:
var foo = File.ReadAllText("NewFolder1/HTMLPage1.htm");
But the error is:
ould not find a part of the path 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\NewFolder1\HTMLPage1.htm'.
How do I read this file?
Use this:
var foo = File.ReadAllText(Server.MapPath("NewFolder1/HTMLPage1.htm"));
If you place the above code in an MVC controller action you can change Server to this.HttpContext.Server to work
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