Trying to create hyperlinks

L

laura

I am writing some code for an intranet and I need to be able to list the
files in folders and subfolders and display them in the browser window as
with hyperlinks.

I've picked up this very useful code on the internet from
www.4guysfromrolla.com. It works a treat, but one problem! If there is a
filename that contains a space, e.g., "my file.doc" the hyperlink only
links up to the space, e.g., it will hyperlink "my" and nothing else.

Here is the code which picks up file names without spaces and is called from
an HTML file as follows (maxitek being the name of my computer)
<a href="dir.asp?PP=C:\Inetpub\wwwroot\&UU=//maxitek">dir.asp</a>

Sub Main()
Dim sPP, sUP, fso, f, fc, ff, fl
sPP = Request.QueryString("PP") 'Physical Path
sUP = Request.QueryString("UP") 'URL Path

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(sPP)
Set fc = f.Files
Set ff = f.SubFolders
For Each fl in fc
Response.Write "<a href=" & sUP & fl.name & ">" & fl.name & "</a> <br>"
Next
Set ff = nothing
Set fso = nothing
Set f = nothing
Set fc = nothing
End Sub

Main()
%>
 
T

Tom Kaminski [MVP]

laura said:
I am writing some code for an intranet and I need to be able to list the
files in folders and subfolders and display them in the browser window as
with hyperlinks.

I've picked up this very useful code on the internet from
www.4guysfromrolla.com. It works a treat, but one problem! If there is a
filename that contains a space, e.g., "my file.doc" the hyperlink only
links up to the space, e.g., it will hyperlink "my" and nothing else.

Here is the code which picks up file names without spaces and is called from
an HTML file as follows (maxitek being the name of my computer)
<a href="dir.asp?PP=C:\Inetpub\wwwroot\&UU=//maxitek">dir.asp</a>

Sub Main()
Dim sPP, sUP, fso, f, fc, ff, fl
sPP = Request.QueryString("PP") 'Physical Path
sUP = Request.QueryString("UP") 'URL Path

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(sPP)
Set fc = f.Files
Set ff = f.SubFolders
For Each fl in fc
Response.Write "<a href=" & sUP & fl.name & ">" & fl.name & "</a> <br>"
Next
Set ff = nothing
Set fso = nothing
Set f = nothing
Set fc = nothing
End Sub

Main()
%>

Make sure the href val is quoted. I like to use single quotes in this case:

Response.Write "<a href='" & sUP & fl.name & "'>" & fl.name & "</a> <br>"
 
L

laura

Tom,

YOU'RE WONDERFUL!!! Thank you so much!! It works.. stupid me for not
realising!

All the best
Laura
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top