Friday, March 18, 2005 2:54 AM bart

Q&A: Self-displaying ASP.NET pages

Question: How to make a page that can show itself (that is, the source code) when creating samples?

Answer: Take a look at http://www.bartdesmet.net/download/hash.aspx. Basically the code is just as simple as this:

string f = Server.MapPath(Request.Path);
using(StreamReader r = new StreamReader(f))
{
   code.Text = Server.HtmlEncode(r.ReadToEnd());
}


Which you can put in an .ascx too, in order to display the .aspx that contains it (cf. Request.Path). So, it becomes as easy as doing a <%@ Register Tagprefix="src" Tagname="view" Src="showcode.ascx" %> together with <src:view runat="server" />.

Del.icio.us | Digg It | Technorati | Blinklist | Furl | reddit | DotNetKicks

Filed under:

Comments

No Comments