Signup · Login
Stardeveloper.com  
Home · Tutorials · Forums · Web Hosting Plans · Faisal Khan's Blog · Contact
Forums : ASP : ASP 3.0 : problem on show.asp page. Signup · Login
Author Thread
problem on show.asp page.
Posted in tutorial: Uploading Files to the Server Hard Disk using plain ASP
·  ahmad
User
Joined: 24 Aug 2005
Total Posts: 5
problem on show.asp page.
Posted: 27 Aug 2005
I have a problem. I tried my best but could not solve is. I have a
page where user selects the folder name from a drop down list. It takes
user to show.asp page, where it how all the files in the folder and
also user can click on them and download them. If I select name of the
folder from the list, on show.asp it shows all the files and their
link. When I click on the link then most of the file which has long
name and have space in their names wont be hyper linked. For example if
files name is Virus Control.vsd or file name is INCIDENT-ACCIDENT
INVESTIGATION REPORT.htm. If I click on them it will say "The page
cannot be found". When I look in the address bar of the browser it
shows address "http://localhost/finalsite/pics//INCIDENT-ACCIDENT"
while it should be
"http://localhost/finalsite/pics/INCIDENT-ACCIDENT%20INVESTIGATION%20R..."
first page is a form where user select the name of the folder where he
wants to see the files.
Can you help me please


<%
' -- show.asp --
' Shows a list of uploaded files


Response.Buffer = True
%>
<html>
<head>
<title>List of uploaded Files</title>
<style>
body, input, td { font-family:verdana,arial; font-size:10pt; }
</style>
</head>
<body>
<p align="center">
<b>List of uploaded Files</b><br>
To upload files click
here
</p>


<%


dim VirtualFolder


VirtualFolder = request.QueryString("foldernam­e")


' File System Object
Dim fso
Set fso = Server.CreateObject("Scripting­.FileSystemObject")


' "Uploaded" Folder
Dim folder
Set folder = fso.GetFolder(Server.MapPath(V­irtualFolder))


If folder.Size > 0 Then
Response.Write "<ul>"
For Each file In folder.Files
Response.Write "<li type=""circle"">"
Response.Write ""
Response.Write "<b>" & file.Name
Response.Write "</b>
"
Response.Write "( Size: " & file.Size & " ) "
Next
Response.Write "</ul>"
Else
Response.Write "<ul><li type=""circle"">No Files Uploaded.</ul>"
End If
%>
</body>
</html>

·  jamisonburrous08
User
Joined: 21 Jul 2007
Total Posts: 3
Quik Fix
Posted: 21 Jul 2007
just replace the " " with %20 in the code

add

REPLACE(file.Name," ", "%20)

Following code is copy / paste ready.

Your code will read:

<%


dim VirtualFolder


VirtualFolder = request.QueryString("foldernam­e")


' File System Object
Dim fso
Set fso = Server.CreateObject("Scripting­.FileSystemObject")


' "Uploaded" Folder
Dim folder
Set folder = fso.GetFolder(Server.MapPath(V­irtualFolder))


If folder.Size > 0 Then
Response.Write "<ul>"
For Each file In folder.Files
REPLACE(file.Name," ", "%20) '<---------REPLACE CODE
Response.Write "<li type=""circle"">"
Response.Write ""
Response.Write "<b>" & file.Name
Response.Write "</b> "
Response.Write "( Size: " & file.Size & " ) "
Next
Response.Write "</ul>"
Else
Response.Write "<ul><li type=""circle"">No Files Uploaded.</ul>"
End If
%>
·  jamisonburrous08
User
Joined: 21 Jul 2007
Total Posts: 3
Sorry fix:
Posted: 21 Jul 2007
I forgot something. With the code I sent you, its still redirecting to the file with a space in the name. I copied the code from your post, and i edited it to work. I tested this script on my own server. Worked well. In the querystring, you must have the "/" at end of folder name. It will display the links, and link them to the filename with the %20 in the file name. You may want to edit your page some more, so you may not allow the browsing of

../
and
./

for security purposes. Sorry about previous post.

Heres the fix:

<%

Dim VirtualFolder

VirtualFolder = Request.QueryString("foldername")
Response.Write VirtualFolder

' File System Object
Dim fso
Set fso = Server.CreateObject("Scripting.FileSystemObject")

' "Uploaded" Folder
Dim folder, filename

Set folder = fso.GetFolder(Server.MapPath("" & VirtualFolder & ""))

If folder.Size > 0 Then
Response.Write "<ul>"
For Each file In folder.Files
filename = Replace(file.Name," ","%20")
Response.Write "<li type=""circle"">"
Response.Write ""
Response.Write "<b>" & file.Name
Response.Write "</b>
"
Response.Write "( Size: " & file.Size & " ) "
Next
Response.Write "</ul>"
Else
Response.Write "<ul><li type=""circle"">No Files Uploaded.</ul>"
End If
%>

Users Who Have Visited This Thread In Last 24 Hours
2 Visitors

Login
UserName Or Email Address:       Password:       Auto-Login:    
· Create New User Account
· Send Forgotten Password by Email
 
© 1999 - 2009 Stardeveloper.com, All Rights Reserved.