473,749 Members | 2,350 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Display Source Code - With Formatting

5 New Member
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 1221
kenobewan
4,871 Recognized Expert Specialist
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 New Member
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
13481
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 to all kinds of websites (ASP,PHP,... or just HTML).There are basically two files in my website: -index.php : shows the main categories along with 3 sample subcategories. -index1.php : displays the subcategories and sites of categories (exactly...
23
3159
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 0H0</p> <p class="Telephone">Telephone: 555-1234 </p> <p class="Fax">Fax: 555-4321</p> </div>
12
20932
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 contains the paths to the pictures. The database consists of two tables: TABLE DATA ID Name LastName
18
3350
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 columns, "scode" and "sname", as 1 column (if not possible then 2 columns will be fine) in the listbox. Can the listbox display 2 columns information from the dataset and how can I do that? Also, I set the property of the listbox to selectionmode...
25
2705
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" long input lines into 2 or more shorter lines before the nth column... etc etc. Now, there are numerous anwers on the web and in the "C answer book", which includes a function to expand the tabs to blanks ( depending upon where the tab is in...
3
4484
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/ HTML 4.01 spec: http://www.w3.org/TR/html401/ validator: http://validator.w3.org/ CSS 2.1 spec: http://www.w3.org/TR/CSS21/ validator: http://jigsaw.w3.org/css-validator/
1
3530
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 (.......) { statement ... }
2
1631
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 any controls that will allow me to do this. We also have access to Infragistic Web controls too. I do not need the user to manipulate the text, I just need to display it.
12
4846
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. The Easter Egg I want to create would send a dump of the data for a particular part number to the screen when a certain secret combination of characters is pressed. If it works out well, I can actually impliment it on our production floor.
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9388
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8256
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.