I am reading a document into a page and then displaying it as source code (this is for an assignment.)
I feel that the output that I am getting is a little hard to read, and want to go beyond the scope of the assignment. I want to add formatting (just like what the [ CODE ] tags on this forum does.
Does anyone know of a simple to implement API for ASP.NET that will allow me to implement this using the method of input below?
Expand|Select|Wrap|Line Numbers
- <script language="C#" runat="server">
- void Page_Load(object sender, System.EventArgs e)
- {
- bool blnEmpty = (Request.QueryString["page"] == null || Request.QueryString["page"].Length == 0);
- if(!blnEmpty){
- string strDocument = Request.QueryString["page"];
- lblDocumentName.Text = strDocument;
- string strPath = Server.MapPath(strDocument);
- string strSourceCode = "";
- try
- {
- strSourceCode = "";
- // Create an instance of StreamReader to read from a file.
- // The using statement also closes the StreamReader.
- using (System.IO.StreamReader sr = new System.IO.StreamReader(strPath))
- {
- string line;
- // Read and display lines from the file until the end of
- // the file is reached.
- while ((line = sr.ReadLine()) != null)
- {
- strSourceCode += line.Replace("<", "<").Replace(">", ">") + "<br/>";
- }
- //strSourceCode = strSourceCode.Replace("<", "<").Replace(">", ">");
- lblSourceCode.Text = "<pre>" + strSourceCode + "</pre>";
- }
- }
- catch (Exception ex)
- {
- // Let the user know what went wrong.
- lblSourceCode.Text = "The Document could not be read:<br/>";
- lblSourceCode.Text += ex.Message;
- }
- } else {
- lblDocumentName.Text = "None";
- lblSourceCode.Text = "No Document Specified.";
- }
- }
- </script>
Expand|Select|Wrap|Line Numbers
- pre {
- white-space: pre-wrap; /* css-3 */
- white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
- white-space: -pre-wrap; /* Opera 4-6 */
- white-space: -o-pre-wrap; /* Opera 7 */
- word-wrap: break-word; /* Internet Explorer 5.5+ */
- }