View Single Post
  #1 (permalink)  
Old March 6th, 2007, 02:56 PM
MArk_dB MArk_dB is offline
Registered User
Join Date: Jan 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Server.mappath and concatenation


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>File Size</TH>
  <TH>Last Modified</TH>

  For Each objFileItem in objFolderContents

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

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

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

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

      <%= objFileItem.DateLastModified %>


Reply With Quote