Show Source Code of Aspx webpage and code file in Browser window
Submitted by jitendramcu on Saturday, November 21, 2009 - 16:23.
Language
For show your source code of aspx page, u have to used System.IO namespace
1) Read Default.aspx File
Aspx file contain both html and aspx server control tag so used File Stream and read 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 physical path
StreamReader sReader = new StreamReader(FilePath);
//Create object of StreamReader
string FileContent = string.Empty;
FileContent = "<pre>" + Server.HtmlEncode(sReader.ReadToEnd()) + "</pre>";
lblaspxsource.Text = FileContent;
sReader.Close();
2)Read Default.aspx.cs File
Use
tage to show 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.Text = FileContent;
sReader.Close();
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Comments
Add new comment
- Add new comment
- 89 views