[ACCEPTED]-Read contents of a file using a relative path in a Web Application-io
Accepted answer
Use Server.MapPath("/path/to/file")
and pass the result of that to File.ReadAllText()
:
String template = File.ReadAllText(Server.MapPath("~/Templates/") + filename);
0
You can use this code snippet as well.
using System.IO;
using System.Web.Hosting;
using (StreamReader sr = new StreamReader(VirtualPathProvider.OpenFile("~/foo.txt")))
{
string content = sr.ReadToEnd();
}
0
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.