473,385 Members | 1,564 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Display Source Code - With Formatting

5
Hi Again,

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
  1. <script language="C#" runat="server">
  2.         void Page_Load(object sender, System.EventArgs e)
  3.         {
  4.             bool blnEmpty = (Request.QueryString["page"] == null || Request.QueryString["page"].Length == 0);
  5.             if(!blnEmpty){
  6.                 string strDocument = Request.QueryString["page"];
  7.  
  8.                 lblDocumentName.Text = strDocument;
  9.  
  10.                 string strPath = Server.MapPath(strDocument);
  11.  
  12.                 string strSourceCode = "";
  13.  
  14.                 try 
  15.                 {
  16.                     strSourceCode = "";
  17.                     // Create an instance of StreamReader to read from a file.
  18.                     // The using statement also closes the StreamReader.
  19.                     using (System.IO.StreamReader sr = new System.IO.StreamReader(strPath)) 
  20.                     {
  21.                         string line;
  22.                         // Read and display lines from the file until the end of 
  23.                         // the file is reached.
  24.                         while ((line = sr.ReadLine()) != null) 
  25.                         {
  26.                             strSourceCode += line.Replace("<", "&lt;").Replace(">", "&gt;") + "<br/>";
  27.                         }
  28.  
  29.                         //strSourceCode = strSourceCode.Replace("<", "&lt;").Replace(">", "&gt;");
  30.                         lblSourceCode.Text = "<pre>" + strSourceCode + "</pre>";
  31.                     }
  32.                 }
  33.                 catch (Exception ex) 
  34.                 {
  35.                     // Let the user know what went wrong.
  36.                     lblSourceCode.Text = "The Document could not be read:<br/>";
  37.                     lblSourceCode.Text += ex.Message;
  38.                 }
  39.             } else {
  40.                 lblDocumentName.Text = "None";
  41.                 lblSourceCode.Text = "No Document Specified.";
  42.             }
  43.         }
  44. </script>
I'm using the CSS below to make sure that the wrapping works as expected:

Expand|Select|Wrap|Line Numbers
  1. pre {
  2.         white-space: pre-wrap;       /* css-3 */
  3.         white-space: -moz-pre-wrap !important;  /* Mozilla, since 1999 */
  4.         white-space: -pre-wrap;      /* Opera 4-6 */
  5.         white-space: -o-pre-wrap;    /* Opera 7 */
  6.         word-wrap: break-word;       /* Internet Explorer 5.5+ */
  7.     }
Thanks
Sep 4 '07 #1
2 1202
kenobewan
4,871 Expert 4TB
Way to go man, I know that you will ace this assignment with a little help from Microsoft:
ASP.NET Configuration API

If only I had thought to go beyond scope on my assignments instead of wasting time chasing girls and playing sports, then I might not have ended as a lowly web developer. My advice study hard and take up karate to fend off those jocks.
Sep 4 '07 #2
dmk
5
Way to go man, I know that you will ace this assignment with a little help from Microsoft:
ASP.NET Configuration API

If only I had thought to go beyond scope on my assignments instead of wasting time chasing girls and playing sports, then I might not have ended as a lowly web developer. My advice study hard and take up karate to fend off those jocks.
Only reason I want to do this is because I have a job for after uni already... I just don't know the language (C#) that they want me to work with ;) might as well get the learning out of the way now.

Thanks for the help, not really what I was looking for... i've only got a couple of weeks for the assignment, and I'm not going THAT far out of my way ;)
Sep 4 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Brian Murphy | last post by:
I have a php-based yahoo-like web directory.I wanna give webmasters the possiblity to integrate my whole directory in their websites with their own formatting.I wanna this inclusion to be possible...
23
by: Mat | last post by:
<div id="container"> <div id="main"> <div id="header"> <p class="Address">123 Fake Street, </p> <p class="City">Crazy City, </p> <p class="Province">Ontario </p> <p class="PostalCode">H0H...
12
by: Wadim Grasza | last post by:
I want to store and display (on a form or a report) multiple pictures per record in an access database. The pictures are not stored within the database. They are stored as files and the database...
18
by: Alpha | last post by:
Hi, I'm working on a Windows applicaton with VS 2003 on windows 2000. I have a listbox that I have binded to a dataset table, "source" which has 3 columns. I would like to display 2 of those...
25
by: mdh | last post by:
Hi Group, Not looking for an answer, but more of an explanation. Thinking back to those heady days when you had the time to do them, may I ask this. Exercise 1-22 asks for a program to "fold"...
3
by: Stan Brown | last post by:
Posted by Pierre Blais in the current RISKS Digest: http://catless.ncl.ac.uk/Risks/24.24.html#subj9 -- Stan Brown, Oak Road Systems, Tompkins County, New York, USA http://OakRoadSystems.com/...
1
by: Sven Fischer | last post by:
After installation of Visual CSharp Studio the current settings of the source code editor are not suitable for me. The brackets are automaticlly set in front of the lines e.g. if (.......) {...
2
by: Sam | last post by:
I have been able to take rft text stored in a SQL database and display it in a RichTextBox control on a windows form. Is there any way to do something similar in an ASP.Net page. I do not see...
12
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I want to plant an Easter Egg in our software. We have a TextBox that is multiline and used to display all sorts of messages on the screen for our operators based on database queries and such. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.