How to show the ASP.NET code to the users

Platform: ASP.NET| Category: Files

Use namespace

  • System.IO
  • System.Text

VB.NET


Protected Function GetCode(filename As String) As String
   	Dim sr As New StreamReader(filename)
	Dim sb As New StringBuilder()
	sb.Append('<code><pre>')
	sb.Append(sr.ReadToEnd())
	sb.Append('</pre></code>')
	sr.Close()
	Return sb.ToString()
	sb = Nothing
	sr = Nothing
End Function ’GetCode

Private Sub Button1_Click(sender As Object, e As System.EventArgs)
   	Response.Write(GetCode((Server.MapPath('WebForm1.aspx') + '.vb')))
End Sub ’Button1_Click

C#


protected string GetCode(string filename)
{
	StreamReader sr =new StreamReader(filename );
	StringBuilder sb =new StringBuilder();
	sb.Append('<code><pre>');
	sb.Append(sr.ReadToEnd());
	sb.Append('</pre></code>');
	sr.Close();
	return sb.ToString();
	sb = null;
	sr = null;
}
private void Button1_Click(object sender, System.EventArgs e)
{
	Response.Write (GetCode(Server.MapPath ('WebForm1.aspx') + '.cs'));
}

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.