Monday, November 22, 2010

C# | Write HTML from external file

I just wrote this for a friend.
It lets us load html dynamically into our page, that is located in some external file.
Commented lines are for debugging purposes

//Response.Write(Path.GetFullPath(Server.MapPath("1\\teste.txt")));
string filePath = Path.GetFullPath(Server.MapPath("1\\teste.txt"));
string fileContents = File.ReadAllText(filePath);
//Response.Write(fileContents);
this.Controls.Add(new LiteralControl(fileContents));

http://www.csharp411.com/c-read-text-file-into-string/

No comments:

Post a Comment