 |
| Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

June 27th, 2007, 03:01 PM
|
|
Authorized User
|
|
Join Date: Apr 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
ASP to list files in a directory dynamically
Hi all.
I am stumped on this one. Not sure what forum to be in...
We have a proprietary program that converts invoices, acknowlegements and quotes from our system and creates a folder named as the customers account number. Inside THAT folder, there are files such as xcel, tiffs and pdfs. How can ASP classic look into that folder and list them into a pulldown window.
The main issue is that we dont know the name of the files until they are created.
Any ideas??
|
|

June 27th, 2007, 06:08 PM
|
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
Place this file in the dir you wish to display, its cut n paste:
<%
Dim strPathInfo, strPhysicalPath
strPathInfo = Request.ServerVariables("PATH_INFO")
strPhysicalPath = Server.MapPath(strPathInfo)
Dim objFSO, objFile, objFileItem, objFolder, objFolderContents
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strPhysicalPath)
Set objFolder = objFile.ParentFolder
Set objFolderContents = objFolder.Files
%>
<HTML>
<HEAD>
<TITLE>Display Directory</TITLE>
</HEAD>
<BODY>
<TABLE cellpadding=5>
<TR align=center>
<td align=left>File Name</td>
<td>File Size</td>
<td>Last Modified</td>
</TR>
<%
For Each objFileItem In objFolderContents
Response.Write "<TR><TD align=left>"
Response.Write objFileItem.Name
Response.Write "</TD><TD align=right>"
Response.Write objFileItem.Size
Response.Write "</TD><TD align=right>"
Response.Write objFileItem.DateLastModified
Response.Write "</TD></TR>"
Next
%>
</TABLE>
</BODY>
</HTML>
Wind is your friend
Matt
|
|

June 28th, 2007, 07:54 AM
|
|
Authorized User
|
|
Join Date: Apr 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Mat41! That was great code and a big help... Now to pick your brain some more as I am new to .asp, but learn quick...
I need that code to go into a folder I will tell dynamically, for example I will use Rs("custctomercode") from a recordset that pulls from a database.
I need that customer code from the database to open only that folder named exactly after that customer code.
So, I need customer 12345678 link to open folder 12345678 that sits on another server via an IP address...
any suggestions???
You are such a help!
|
|

June 28th, 2007, 07:05 PM
|
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
Probably a little to much help. Please be aware forums are not places where you ususlly get complete solutions. I found FSO code a little tricky myself. I guess thats why I, well, gave you a little to much help which can not be good for your learning curve. The code above is not on the forum however the following code is. The next solution you want, try searching here before posting (and ask google of course)
This code gives you a great deal of FSO information. Place this file anywhere on your web server and alter the following line with a valid dir name(s):
<% ListFolderContents(Server.MapPath("/someValidDirName")) %>
You may alo do something like:
<% ListFolderContents(Server.MapPath("/someValidDirName/someOtherValidDirName")) %>
-----------------------------start code-------------------------------
<% OPTION EXPLICIT %>
<% 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("<li><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." & vbCrLf)
Response.Write("[list]" & vbCrLf)
'Display a list of sub folders.
for each item in folder.SubFolders
ListFolderContents(item.Path)
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> - " & item.Size & " bytes, last modified on " & item.DateLastModified & ".</li>" & vbCrLf)
next
Response.Write("</ul>" & vbCrLf)
Response.Write("</li>" & 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 %>
<html>
<head>
<title>ASP Detailed Directory Listing</title>
</head>
<body>
[list]
<% ListFolderContents(Server.MapPath("/ohs/admin")) %>
</ul>
</body>
</html>
-----------------------------finish code------------------------------
Play with the code, learn using trial and error and looking at useful links (such as the one Imar gave you) what each line does.
Wind is your friend
Matt
|
|

July 19th, 2007, 07:44 AM
|
|
Authorized User
|
|
Join Date: Apr 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Mat41....
I have a tiny dilemma on this code now...
Code works great! But...
I need to make the last directory which is a folder on the server to change dynamically.
This folder name will be pulled from the database.
I have sales reps that each have rep codes. I then have each rep code FOLDER on the server.
I need each rep to specifically get called up from their OWN folder.
so for example:
using:
<% ListFolderContents(Server.MapPath("/salesreps/JR")) %>
I need the "JR" to change. Hoiw would I wriet that area to use
<%= rstSearch.Fields("repcode").Value %>
in that spot?
Thanks.
|
|

July 25th, 2007, 10:19 PM
|
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
Hello, I have been away on holiday...
Have you tried this?
<% ListFolderContents(Server.MapPath("/salesreps/" & rstSearch.Fields("repcode").Value & "")) %>
Wind is your friend
Matt
|
|

July 27th, 2007, 07:51 AM
|
|
Authorized User
|
|
Join Date: Apr 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
mat41,
You are awesome! Worked like a charm. This was stumping me and you have made me see the light!
I seem to get confused in ASP with all those extra commas everywhere""" '""''' ''"""
I know to open an clsed the staements when needed, but i always seem to have extra commas. Not sure what they always do. the "&" also confuses me as well.
Thanks again.
|
|

July 29th, 2007, 05:56 PM
|
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
Glad it worked...
Do you use a code editor EG Homesite? If so the color coding should help you with all the " and ' and & If not using one will help you big time. Otherwise the old trial and error method is the best way to learn.
Wind is your friend
Matt
|
|

August 1st, 2007, 09:53 AM
|
|
Authorized User
|
|
Join Date: Apr 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Mat41,
I have been searching everywhere to see proper syntax to change the "item.DateLastModified" in the code to only show the date WITHOUT the time. any clue? item.Date doesnt work...
Thanks a million.
|
|
 |