I developed a secure ASP page for the company I work for. There is a landing (login page), which after you have been authenticated, you get to a page with links to several subpages. Each subpage has a folder structure. For example: there is a heading for the minutes of the meeting, and then under it there are also indents - links that link to PDF files containing information. There may be 3 or 4 headings with documents below.
In the original version, a PHP script was launched and would synchronize the live site on the server from the folder structure that would be simulated on the live site. So if I had a folder called Folder1 and subfolders named test1 test2 test3 .., then the live site would display them accordingly. Since the site is now in ASP and not PHP, the PHP script no longer works (since PHP does not work well with ASP).
I found a snippet on the Internet that works somewhat for what I'm trying to achieve (e.g. Folder / Subfolder / File Name structure), however, I'm currently stuck in linking files so that they open when clicked. I continue to see% 25 in the file name. I know that% 20 is the same as empty space, and since I am dealing with file and folder names that contain spaces, this seems to be my problem. I tried adding in% 20, but spaces become "% 2520".
If you look at the code below, there is a link at the bottom that calls "MapURL". I have a link commented at the moment when I was trying to figure out where% 25 came from. Does anyone have any thoughts on how to make links work?
Here is a snippet.
dim path
path = "PATH TO THE FOLDER ON THE SERVER"
ListFolderContents(path)
sub ListFolderContents(path)
dim fs, folder, file, item, url
set fs = CreateObject("Scripting.FileSystemObject")
set folder = fs.GetFolder(path)
'Display the target folder and info.
Response.Write("<ul><b>" & folder.Name & "</b>") '- " _
' & folder.Files.Count & " files, ")
'if folder.SubFolders.Count > 0 then
' Response.Write(folder.SubFolders.Count & " directories, ")
'end if
'Response.Write(Round(folder.Size / 1024) & " KB total." _
' & "</ul>" & vbCrLf)
Response.Write("<ul>" & vbCrLf)
'Display a list of sub folders.
for each item in folder.SubFolders
ListFolderContents(item)
next
'Display a list of files.
for each item in folder.Files
'url = MapURL(item.path)
'Response.Write("<li><a href=" & url & ">" & item.Name & "</a> - " _
Response.Write("<li><a href=" & Replace(item.path," ","%") & ">" & item.Name & "</a> - " _
& item.Name & "</a>" _
& "</li>" & vbCrLf)
next
Response.Write("</ul>" & vbCrLf)
Response.Write("</ul>" & vbCrLf)
end sub
function MapURL(path)
dim rootPath, url
'Convert a physical file path to a URL for hypertext links.
rootPath = Server.MapPath("/")
url = Right(path, Len(path) - Len(rootPath))
MapURL = Replace(url, "\", "/")
end function