Show Source Code of Aspx webpage and code file in Browser window – Free Source Code

Posted on

For present your supply code of aspx web page, u need to used System.IO namespace
1) Learn Default.aspx File
Aspx file comprise each html and aspx server management tag so used File Stream and browse a aspx file.
Server.HtmlEncode (String val) takes a string argument and return all aspx code as a string.
string FilePath = Server.MapPath(“Default.aspx”);
//get the bodily path
StreamReader sReader = new StreamReader(FilePath);
//Create object of StreamReader
string FileContent = string.Empty;
FileContent = “<pre>” + Server.HtmlEncode(sReader.ReadToEnd()) + “</pre>”;
lblaspxsource.Textual content = FileContent;
sReader.Shut();
2)Learn Default.aspx.cs File
Use tage to indicate your aspx(C#,VB) code into browser window
string FilePath = Server.MapPath("Default.aspx.cs");
StreamReader sReader = new StreamReader(FilePath);
string FileContent = string.Empty;
FileContent = "<pre><code>" + Server.HtmlEncode(sReader.ReadToEnd()) + "</code></pre>";
lblsourcecodeCSFile.Textual content = FileContent;
sReader.Shut();