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?
[CODE=c]<script language="C#" runat="server">
void Page_Load(objec t sender, System.EventArg s e)
{
bool blnEmpty = (Request.QueryS tring["page"] == null || Request.QuerySt ring["page"].Length == 0);
if(!blnEmpty){
string strDocument = Request.QuerySt ring["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.Stre amReader sr = new System.IO.Strea mReader(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.R eplace("<", "<").Replace (">", ">");
lblSourceCode.T ext = "<pre>" + strSourceCode + "</pre>";
}
}
catch (Exception ex)
{
// Let the user know what went wrong.
lblSourceCode.T ext = "The Document could not be read:<br/>";
lblSourceCode.T ext += ex.Message;
}
} else {
lblDocumentName .Text = "None";
lblSourceCode.T ext = "No Document Specified.";
}
}
</script>[/CODE]
I'm using the CSS below to make sure that the wrapping works as expected:
[CODE=css]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+ */
}[/CODE]
Thanks
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?
[CODE=c]<script language="C#" runat="server">
void Page_Load(objec t sender, System.EventArg s e)
{
bool blnEmpty = (Request.QueryS tring["page"] == null || Request.QuerySt ring["page"].Length == 0);
if(!blnEmpty){
string strDocument = Request.QuerySt ring["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.Stre amReader sr = new System.IO.Strea mReader(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.R eplace("<", "<").Replace (">", ">");
lblSourceCode.T ext = "<pre>" + strSourceCode + "</pre>";
}
}
catch (Exception ex)
{
// Let the user know what went wrong.
lblSourceCode.T ext = "The Document could not be read:<br/>";
lblSourceCode.T ext += ex.Message;
}
} else {
lblDocumentName .Text = "None";
lblSourceCode.T ext = "No Document Specified.";
}
}
</script>[/CODE]
I'm using the CSS below to make sure that the wrapping works as expected:
[CODE=css]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+ */
}[/CODE]
Thanks
Comment