bodanon
asked on
ASP class object: call a sub from a hyperlink
I am experimenting with Class objects in classic ASP/vbscript on my local machine testing server.
I have a Sub within a Class that lists subfolders in a directory.
It is rather simple. I use a "For Each" to iterate throught the directory attaching a hyperlink to each folder listing that should list the files within the subfolder when clicked.
This works fine (and I especially like the fact that it reveals no path information in the address bar), but when I click the hyperlink it shows the directory contents in internet explorer revealing the exact path information.
What I would like to do is call another sub which lists files within the subfolder when the hyperlink is clicked without changing pages and without revealing path information.
can this be done?
If so, how?
Here is the code:
<%
Class clsFman
Public Sub Class_Initialize()
Call lstFoldrs
End Sub
Private Sub lstFoldrs
Dim oFSO, oFolder, curFolder, oSubFolder, oFile
Set oFSO = Server.CreateObject("Scrip ting.FileS ystemObjec t")
curFolder = Server.MapPath("../../path ")
Set oFolder = oFSO.GetFolder(curFolder)
Response.Write("<table width=480px align=center border=0 cellpadding=0 cellspacing=2>")
Response.Write("<tr bgcolor=#FFCC00 height=20>")
Response.Write("<td align=center width=250><b><font size=1 face=Tahoma>FOLDER</font>< /b></td>")
Response.Write("<td align=center width=100><b><font size=1 face=Tahoma>CLIENT NAME</font></b></td>")
Response.Write("<td align=center width=100><b><font size=1 face=Tahoma>CREATED ON</font></b></td>")
Response.Write("<td align=center width=75><b><font size=1 face=Tahoma>PROJECT</font> </b></td>" )
Response.Write("<td align=center width=35><font size=1 face=Tahoma>delete</font>< /td>")
Response.Write("</tr>")
For Each oSubFolder in oFolder.SubFolders
Response.Write("<tr bgcolor=#F8F8F8>")
Response.Write("<td height=18 align=left valign=middle><b><font face=Tahoma color=666666> <a href=" & oFolder &"/" & oSubFolder.Name &"/>" & oSubFolder.Name &"</a></font></b></td>")
Response.Write("<td></td>" )
Response.Write("<td></td>" )
Response.Write("<td></td>" )
Response.Write("<td></td>" )
Response.Write("</tr>")
Next
Response.Write("</table>")
End Sub
Private Sub lstFiles
Dim oFSO, oFolder, curFolder, oSubFolder, oFile
Set oFSO = Server.CreateObject("Scrip ting.FileS ystemObjec t")
curFolder = Server.MapPath("../../path ")
Set oFolder = oFSO.GetFolder(curFolder)
Response.Write("<table width=480px align=center border=0 cellpadding=0 cellspacing=2>")
Response.Write("<tr bgcolor=#FFCC00 height=20>")
Response.Write("<td align=center width=250><b><font size=1 face=Tahoma>FOLDER</font>< /b></td>")
Response.Write("<td align=center width=100><b><font size=1 face=Tahoma>CLIENT NAME</font></b></td>")
Response.Write("<td align=center width=100><b><font size=1 face=Tahoma>CREATED ON</font></b></td>")
Response.Write("<td align=center width=75><b><font size=1 face=Tahoma>PROJECT</font> </b></td>" )
Response.Write("<td align=center width=35><font size=1 face=Tahoma>delete</font>< /td>")
Response.Write("</tr>")
For Each oFile in oFolder.Files
Dim X
X = X + 1
If X Mod 2 then
Response.Write("<tr bgcolor=#E4E4E4>")
Else
Response.Write("<tr bgcolor=#F8F8F8>")
End If
Response.Write("<td height=18 width=250 align=left valign=middle><font face=Tahoma> <a href='" & oSubFolder &"' & '" & oFile.Name & "'>" & oFile.Name &"</a></font></td>")
Response.Write("<td width=75 align=left valign=middle><font face=Tahoma> </font>< /td>")
Response.Write("<td width=100 align=left valign=middle><font face=Tahoma> " & FormatDateTime(oFile.DateC reated, 2) &"</font></td>")
Response.Write("<td width=75 align=left valign=middle><font face=Tahoma> </font>< /td>")
Response.Write("<td width=35 align=center valign=middle><b><font face=Tahoma>X</font></b></ td>")
Response.Write("</tr>")
Next
Response.Write("</table>")
End Sub
Public Sub Class_Terminate()
End Sub
End Class
%>
Thanks in Advance
I have a Sub within a Class that lists subfolders in a directory.
It is rather simple. I use a "For Each" to iterate throught the directory attaching a hyperlink to each folder listing that should list the files within the subfolder when clicked.
This works fine (and I especially like the fact that it reveals no path information in the address bar), but when I click the hyperlink it shows the directory contents in internet explorer revealing the exact path information.
What I would like to do is call another sub which lists files within the subfolder when the hyperlink is clicked without changing pages and without revealing path information.
can this be done?
If so, how?
Here is the code:
<%
Class clsFman
Public Sub Class_Initialize()
Call lstFoldrs
End Sub
Private Sub lstFoldrs
Dim oFSO, oFolder, curFolder, oSubFolder, oFile
Set oFSO = Server.CreateObject("Scrip
curFolder = Server.MapPath("../../path
Set oFolder = oFSO.GetFolder(curFolder)
Response.Write("<table width=480px align=center border=0 cellpadding=0 cellspacing=2>")
Response.Write("<tr bgcolor=#FFCC00 height=20>")
Response.Write("<td align=center width=250><b><font size=1 face=Tahoma>FOLDER</font><
Response.Write("<td align=center width=100><b><font size=1 face=Tahoma>CLIENT NAME</font></b></td>")
Response.Write("<td align=center width=100><b><font size=1 face=Tahoma>CREATED ON</font></b></td>")
Response.Write("<td align=center width=75><b><font size=1 face=Tahoma>PROJECT</font>
Response.Write("<td align=center width=35><font size=1 face=Tahoma>delete</font><
Response.Write("</tr>")
For Each oSubFolder in oFolder.SubFolders
Response.Write("<tr bgcolor=#F8F8F8>")
Response.Write("<td height=18 align=left valign=middle><b><font face=Tahoma color=666666> <a href=" & oFolder &"/" & oSubFolder.Name &"/>" & oSubFolder.Name &"</a></font></b></td>")
Response.Write("<td></td>"
Response.Write("<td></td>"
Response.Write("<td></td>"
Response.Write("<td></td>"
Response.Write("</tr>")
Next
Response.Write("</table>")
End Sub
Private Sub lstFiles
Dim oFSO, oFolder, curFolder, oSubFolder, oFile
Set oFSO = Server.CreateObject("Scrip
curFolder = Server.MapPath("../../path
Set oFolder = oFSO.GetFolder(curFolder)
Response.Write("<table width=480px align=center border=0 cellpadding=0 cellspacing=2>")
Response.Write("<tr bgcolor=#FFCC00 height=20>")
Response.Write("<td align=center width=250><b><font size=1 face=Tahoma>FOLDER</font><
Response.Write("<td align=center width=100><b><font size=1 face=Tahoma>CLIENT NAME</font></b></td>")
Response.Write("<td align=center width=100><b><font size=1 face=Tahoma>CREATED ON</font></b></td>")
Response.Write("<td align=center width=75><b><font size=1 face=Tahoma>PROJECT</font>
Response.Write("<td align=center width=35><font size=1 face=Tahoma>delete</font><
Response.Write("</tr>")
For Each oFile in oFolder.Files
Dim X
X = X + 1
If X Mod 2 then
Response.Write("<tr bgcolor=#E4E4E4>")
Else
Response.Write("<tr bgcolor=#F8F8F8>")
End If
Response.Write("<td height=18 width=250 align=left valign=middle><font face=Tahoma> <a href='" & oSubFolder &"' & '" & oFile.Name & "'>" & oFile.Name &"</a></font></td>")
Response.Write("<td width=75 align=left valign=middle><font face=Tahoma> </font><
Response.Write("<td width=100 align=left valign=middle><font face=Tahoma> " & FormatDateTime(oFile.DateC
Response.Write("<td width=75 align=left valign=middle><font face=Tahoma> </font><
Response.Write("<td width=35 align=center valign=middle><b><font face=Tahoma>X</font></b></
Response.Write("</tr>")
Next
Response.Write("</table>")
End Sub
Public Sub Class_Terminate()
End Sub
End Class
%>
Thanks in Advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> but it seems they are capable of providing the same capabilities as a COM object
Well, yes and no.
No, because many COM objects are programmed in more advanced languages then VBScript, and bring the possibilities of those languages to VBScript. With a pure VBScipt Class you can not add non-VBScript functionality to VBScript (of course).
Yes, because a script-class is an object. And if you succeed in creating a script-class that does the same as a COM object, you will find that a script class might even be faster then a COM object. At least I found some evidence of that here: http://www.taka.nl/programming/asp/comparing_fileupload.asp
Well, yes and no.
No, because many COM objects are programmed in more advanced languages then VBScript, and bring the possibilities of those languages to VBScript. With a pure VBScipt Class you can not add non-VBScript functionality to VBScript (of course).
Yes, because a script-class is an object. And if you succeed in creating a script-class that does the same as a COM object, you will find that a script class might even be faster then a COM object. At least I found some evidence of that here: http://www.taka.nl/programming/asp/comparing_fileupload.asp
ASKER
You are right. Class objects are a bit more intricate than I realized, but it seems they are capable of providing the same capabilities as a COM object (if coded right).
This definatley points me in the right direction.
Thanks for the insight.