Loading

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

Submitted by: 
Language: 
Visitors have accessed this post 9291 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;
sReader.Close();

2)Read Default.aspx.cs File
Use

  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();



Tags: 

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

can u send projects on online course using asp.net with source code

hi,

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

Add new comment

(If you're a human, don't change the following field)
Your first name.
(If you're a human, don't change the following field)
Your first name.
(If you're a human, don't change the following field)
Your first name.

Filtered HTML

  • 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.