|
xxx
Source Code Shower
by Charles Carroll
Here is code I use at site to show a directory of samples
filename=/experiments/utilitybelt/vernext/index.aspx
<%@ Register TagPrefix="Code" tagname="Show" src="\experiments\usercontrols\scriptviewer.ascx"%>
<html><head>
<title>CodeShow Test</title></head>
<body bgcolor="#FFFFFF">
<Code:Show Path="/experiments/utilitybelt/vernext" filename="index.aspx" wildcard="*.*" runat="server"/>
</body></html>
filename=/experiments/metabuilders/index.aspx
<%@ Register TagPrefix="Code" tagname="Show" src="\experiments\usercontrols\scriptviewer.ascx"%>
<html><head>
<title>CodeShow Test</title></head>
<body bgcolor="#FFFFFF">
<Code:Show Path="/experiments/metabuilders" filename="index.aspx" wildcard="*.aspx" runat="server"/>
</body></html>
filename=/experiments/training/cs/index.aspx
<%@ Register TagPrefix="Code" tagname="Show" src="\experiments\usercontrols\scriptviewer.ascx"%>
<html><head>
<title>CodeShow Test</title></head>
<body bgcolor="#FFFFFF">
<Code:Show Path="/experiments/training/cs" filename="index.aspx" runat="server"/>
</body></html>
Here is UserControl that does the hard work
filename=/experiments/usercontrols/scriptviewer.ascx
<%@ Import Namespace="System.IO" %>
<%@ Assembly src="/experiments/utilitybelt/vernext/stable/utilitybelt.vb" %>
<script language="VB" runat="server">
dim ub1 as new learnAsp.UtilityBelt
public path as string
public wildcard as string="*.*"
sub Page_Load(S as Object, E as EventArgs)
Dim strFileName as string=""
If request.querystring("")=""
ShowAll(Path)
End If
TRY
strFileName=Path & "/" & request.querystring("file")
If strFileName<>Path & "/"
dim sb1 as new stringbuilder
with sb1
.append("<h3>")
.append(strFileName)
.append("</h3>")
.append(ub1.ScriptColorCode(strFileName))
end with
LitCodeShow.Text=sb1.ToString()
end if
CATCH exc1 as exception
page.controls.add(new literalcontrol(exc1.Message()))
END TRY
end sub
Sub ShowAll(strPath as string)
Dim filecollection as string()
Dim myFileInfo as FileInfo
FileCollection=Directory.GetFiles(server.mappath(strPath),wildcard)
dim intcountfiles as integer=FileCollection.Length
Dim intfilecurrent as integer
dim sb1 as new stringbuilder
dim strFilenamecurrent as string
For intfilecurrent=0 to intcountfiles-1
myFileInfo=new FileInfo(FileCollection(intFileCurrent))
strFilenameCurrent=myFileInfo.Name.ToString().tolower()
IF strFilenameCurrent="index.aspx"
ELSE
with sb1
.append("<<a href='")
.append(strFileNameCurrent)
.append("'>Run Code")
.append("</a>> ")
.append("<<a href='index.aspx?file=")
.append(strFileNameCurrent)
.append("#code'>Show Source")
.append("</a>> ")
.append(strFileNameCurrent)
.append(system.environment.newline)
.append("<br>")
end with
END IF
next
litScripts.Text=sb1.ToString()
end Sub
</script>
<html><head><title>Show Me The Scripts</title></head>
<body bgcolor="#FFFFFF">
<font face="Verdana"><h3>Show Me The Scripts</h3>
<asp:literal id="litExc" runat="server" />
<ASP:literal id="litScripts" runat="server" />
<A Name="code"><ASP:literal id="litCodeShow" runat="server" /></a>
</font>
</body></html>
 |  |  |
 |
There are many worthy charities!!. But perhaps help starving children in Africa or South America AND help Charles too.
a $5 tip buys him lunch at McDonalds,
a $20 tip buys his kid Hitoshi a new computer game,
a $39 tip buys his daughter Michiko a few nice outfits.
See our donor list.
|  |
 |  |  |
|
|
|
|