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

Submitted by: 
Visitors have accessed this post 9690 times.

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;

2)Read Default.aspx.cs File

  1. tage to show your aspx(C#,VB) code into browser window
  2. string FilePath = Server.MapPath("Default.aspx.cs");
  3. StreamReader sReader = new StreamReader(FilePath);
  4. string FileContent = string.Empty;
  5. FileContent = "&lt;pre&gt;&lt;code&gt;" + Server.HtmlEncode(sReader.ReadToEnd()) + "&lt;/code&gt;&lt;/pre&gt;";
  6. lblsourcecodeCSFile.Text = FileContent;
  7. 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 for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.


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.


can u send projects on online course using with source code


Do you know how we can read the source code off a aspx in php

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe>
  • You may insert videos with [video:URL]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.