Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

URL, UNC path script issues...

Status
Not open for further replies.

MojoZig

Technical User
Sep 27, 2005
61
US
This should be an easy quick question:

I have this code below which I acquired from this forum I believe. It works great but I now need to change it from a local folder on the intranet server to a unc path. This is the code that works:

Code:
	  <!-- List these three folders. -->
<ul>
<% ListFolderContents(Server.MapPath("/Departments/Department_folder")) %>

<!--  
% ListFolderContents(Server.MapPath("/dhtml")) %>
% ListFolderContents(Server.MapPath("/js")) %>
-->

</ul>

<% 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("<ul>" & 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 %>

Now, I know I need to make this change at the top and remove the Server.Mappath portion and change it out to the UNC path as such:

Code:
<% ListFolderContents(("\\fileserver\Departments\Department_Folder\")) %>

The documents list on the asp page with no problems but the links aren't working properly and I know it has something to do with this part:

Code:
     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, "\", "/")

What do I need to do here? without editing this part, it's trimming everything except "cuments\" ... so a linked document can't open and the path looks like:


I tried running the original script in the new location with a virtual directory but the script won't see the path via a virtual directory which is why I'm doing it this way now ... unless I missed something ...

Any help? I think i have all my facts in line!:eek:)

Thanks!

MojoZig
 
Give this a try:

Code:
<%@ LANGUAGE="VBSCRIPT" %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="The Spider's Parlor">
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Customer Support Download Page</TITLE>
</HEAD>
<BODY>
<!--
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' COPYRIGHT (c) 2004 All Rights Reserved
' DATE  : 3/16/2004
-->

<table height=100%>
<tr>
	<td bgcolor="84A5C6" width=17% height=100%></td>
	<td valign=top>
		
		<%

		
		set directory=server.createobject("scripting.filesystemobject")
		set allfiles=directory.getfolder(server.mappath("/download2/"))
		
		' Lists all the files found in the directory
		For each directoryfile in allFiles.files 
				
			%>
			<a href=/download2/<%
			' Write out the name of the document
			response.write server.urlencode(directoryfile.name) %>><% response.write directoryfile.name %></a><br>
		<% 
				
		' End for next loop to list documents
		next 
				
		%> 
		
		
	</td>
	<td bgcolor="84A5C6" width=17% height=100%></td>
</tr>
</table>


</BODY>
</HTML>

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top