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 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." 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 Basics 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 Search this Thread Display Modes
  #1 (permalink)  
Old March 6th, 2007, 02:56 PM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Server.mappath and concatenation

Hi

Can someone give me a hand with this problem.

I am trying to view the contents of a folder. The problem seems to be how I map to the directory.

When I use:
strPathInfo = request.ServerVariables(PATH_INFO)
strPhysicalPath = Server.MapPath(strPathInfo)

It lists the files is the directory where the showfiles.asp file resides.

I actually want it to show the contents of a directory which varies with the concatenated variables as shown below to give a unique path (which is actually dependant on the user details when he/she logs in). Folders are created through another process so there is a folder for each physical path.

Sorry if I havent explained this very well and any help greatly appreciated.

My Code

<%

Dim strpathinfo
Dim strPhysicalPath
Dim folderName
Dim city
Dim company

folderName = Request.QueryString("id") 'passed from login
city = Request.querystring("city") 'passed from login
company = Request.Querystring("company") 'passed from login

  strPhysicalPath = Server.MapPath(".")&"\" & company & "\" & city & "\" & foldername 'path with concatenated variables to give unique physical path

  'response.Write(strPhysicalPath) shows physical path held by variable

  Dim objFSO, objFile, objFileItem, objFolder, objFolderContents
  Set objFSO = CreateObject("Scripting.FileSystemObject")

  Set objFile = objFSO.GetFolder(strPhysicalPath)
  Set objFolder = objFile.ParentFolder
  Set objFolderContents = objFolder.Files
%>

<TABLE cellpadding=5>
<TR align=center>
  <TH align=left>File Name</TH>
  <TH>Type</TH>
  <TH>File Size</TH>
  <TH>Last Modified</TH>
</TR>

<%
  For Each objFileItem in objFolderContents
%>

    <TR>
      <TD align=left>
      <A HREF="<%= objFileItem.Name %>">

      <%= objFileItem.Name %>
      </A>
      </TD>
      <TD align=right>

      <%= objFileItem.type %>
      </TD>
      <TD align=right>

      <%= objFileItem.size %>
      </TD>
      <TD align=right>

      <%= objFileItem.DateLastModified %>
      </TD>
    </TR>

<%
  Next
%>



Reply With Quote
  #2 (permalink)  
Old March 6th, 2007, 02:57 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Well what is the problem you are having exactly? The directory that is created with MapPath is incorrect or??

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
Reply With Quote
  #3 (permalink)  
Old March 6th, 2007, 03:20 PM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The mappath concatenation gives me the correct physical path and the code executes correctly except it does not show a list of the files contained within the folder.

Reply With Quote
  #4 (permalink)  
Old March 6th, 2007, 03:30 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

try:

For Each objFileItem in objFile.Files
'code...
Next

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
Reply With Quote
  #5 (permalink)  
Old March 6th, 2007, 03:34 PM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You are a star!!
Many thanks

Reply With Quote
  #6 (permalink)  
Old March 6th, 2007, 03:48 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

No problem, glad you got it working.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
objFSO, Server.mappath, etc in this book? cJeffreywang BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 0 September 12th, 2007 04:54 PM
Server.MapPath johanyu ASP.NET 1.0 and 1.1 Basics 0 October 19th, 2004 12:42 AM
Server.MapPath stu9820 Classic ASP Basics 1 January 9th, 2004 04:16 PM
server.mappath kyootepuffy Classic ASP Databases 1 September 5th, 2003 04:17 PM



All times are GMT -4. The time now is 10:08 AM.


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