How to show the ASP.NET code file

Use a simple function, which will show the text of the file. You will need the pass the path of the file to the function. This path should be the absolute path and hence you should use the Server.MapPath while calling this function.

Here is the code to the work

 protected string GetCode(string filename)
    {
        StreamReader sr = new StreamReader(filename);
        StringBuilder sb = new StringBuilder();
        sb.Append("<code><pre>");
        sb.Append(sr.ReadToEnd());
        sb.Append("");
        sr.Close();
        return sb.ToString();
        sb = null;
        sr = null;
    }
Reactions

Post a Comment

0 Comments

Close Menu