Wrox Programmer Forums
| 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 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
  #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
%>



  #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
================================================== =========
  #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.

  #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
================================================== =========
  #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

  #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
================================================== =========


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





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