Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Professional
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 27th, 2007, 04:01 PM
Authorized User
Points: 483, Level: 7
Points: 483, Level: 7 Points: 483, Level: 7 Points: 483, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2007
Location: Edgewood, NY, USA.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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??

Reply With Quote
  #2 (permalink)  
Old June 27th, 2007, 04:06 PM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,957
Thanks: 79
Thanked 1,556 Times in 1,533 Posts
Default

Hi there,

Take a look at the FileSystemObject and its GetFolder and GetFile methods:

http://msdn2.microsoft.com/en-us/library/2z9ffy99.aspx

Cheers,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
Reply With Quote
  #3 (permalink)  
Old June 27th, 2007, 07:08 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

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
Reply With Quote
  #4 (permalink)  
Old June 28th, 2007, 08:54 AM
Authorized User
Points: 483, Level: 7
Points: 483, Level: 7 Points: 483, Level: 7 Points: 483, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2007
Location: Edgewood, NY, USA.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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!

Reply With Quote
  #5 (permalink)  
Old June 28th, 2007, 08:05 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

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
Reply With Quote
  #6 (permalink)  
Old July 19th, 2007, 08:44 AM
Authorized User
Points: 483, Level: 7
Points: 483, Level: 7 Points: 483, Level: 7 Points: 483, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2007
Location: Edgewood, NY, USA.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
  #7 (permalink)  
Old July 25th, 2007, 11:19 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Hello, I have been away on holiday...

Have you tried this?
<% ListFolderContents(Server.MapPath("/salesreps/" & rstSearch.Fields("repcode").Value & "")) %>



Wind is your friend
Matt
Reply With Quote
  #8 (permalink)  
Old July 27th, 2007, 08:51 AM
Authorized User
Points: 483, Level: 7
Points: 483, Level: 7 Points: 483, Level: 7 Points: 483, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2007
Location: Edgewood, NY, USA.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
  #9 (permalink)  
Old July 29th, 2007, 06:56 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

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
Reply With Quote
  #10 (permalink)  
Old August 1st, 2007, 10:53 AM
Authorized User
Points: 483, Level: 7
Points: 483, Level: 7 Points: 483, Level: 7 Points: 483, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2007
Location: Edgewood, NY, USA.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Switching list content dynamically ... asearle XSLT 1 September 24th, 2006 12:41 PM
View Files in a Directory echovue Access 1 October 15th, 2005 03:36 PM
list asp varialbes dynamically marco_1 Classic ASP Professional 2 June 14th, 2004 02:25 PM
update list/menu value dynamically anjila Classic ASP Basics 1 February 5th, 2004 05:41 AM



All times are GMT -4. The time now is 03:19 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.