p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Classic ASP Basics (http://p2p.wrox.com/forumdisplay.php?f=61)
-   -   Server.mappath and concatenation (http://p2p.wrox.com/showthread.php?t=54989)

MArk_dB March 6th, 2007 02:56 PM

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
%>




dparsons March 6th, 2007 02:57 PM

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

MArk_dB March 6th, 2007 03:20 PM

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.


dparsons March 6th, 2007 03:30 PM

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

MArk_dB March 6th, 2007 03:34 PM

You are a star!!
Many thanks


dparsons March 6th, 2007 03:48 PM

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


All times are GMT -4. The time now is 11:38 PM.

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