Wrox Programmer Forums
|
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
 
Old November 21st, 2003, 03:32 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to acdsky
Default File name lookup

Hi

I need to find a way to make files available for download... but the files change daily and there are 100+ of them. I was thinking to create a predefined folder structure and use some kind of script to lookup the file names and diplay it as a hyperlink within a table or a page.

Does anyone know if this is possible using asp/VBS/JS with a FSO function or something?

Regards
M



Such is Life!
 
Old November 21st, 2003, 03:57 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Yes very possible.
This is a good link but there are others out there.
http://www.stardeveloper.com/article...1050301&page=1

If you are uploading the files to the server rather than just putting them there.I would suggest listing the file names and locations in a database table when uploading and using that for your links. It would be a lot less work for your machine than fso.

======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
 
Old November 21st, 2003, 08:06 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to acdsky
Default

I Have managed to put somethin together but I have one problem. It enables you to browse the folders but I have a problem opening the files cause it opens it from the "val" value instead of the url.

href values return the following:
Folder = http://whatever/files.asp?drive=c:File = file:///c:\filename

I am not able to use the file.asp?drive=c:\ to open the file. I have tried using a URL= and replace that with the second link = val &S but then I have a problem with sub folders...

Any help would be appreciated....below the code:

*****************************
<%
'on error resume next

dim val

Dim FSO, f, f1, fc, s, fsub, link


val=request.querystring("drive")

if val="" then
    val="C:\Inetpub\wwwroot\MSAP\"
else
    if len(val)=1 then
        val= val & ":\"
    end if
end if

link=val

Set FSO = CreateObject("Scripting.FileSystemObject")
Set f = FSO.GetFolder(val)
Set fc = f.Files
Set fsub = f.SubFolders
%>

<html>

<head>
<style>
a {text-decoration:none;}
a:hover {text-decoration:underline;}
</style>

<meta http-equiv="Content-Language" content="pt-br">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>None</title>
<base target="_self">
</head>


<p style="margin-top: 0; margin-bottom: 0"><b>
File Names<%=val%></b>

</b></p>

<table border="0" width="50%" height="56">

<%
For Each f1 in fsub
s = s & f1.name
link=""
link = val & s&"\"
s = s & vbCrLf
%>
<tr>
    <td width="100%" height="24"><img border="0" src="folder.gif" width="23" height="22" align="absmiddle">
      <a href="files.asp?drive=<%= link %>"><%=s%></a></td>
</tr>
<%
s=""
Next
s=""
%>

<%
For Each f1 in fc
s = s & f1.name
link=""
link = val & s
s = s & vbCrLf
%>
  <tr>
    <td width="100%" height="24"><a href="<%= link %>" target="blank"><img border="0" src="file.gif" width="25" height="26" align="absmiddle"><%=s%></a></td>
  </tr>
<%
s=""
Next
%>

</table>

<p></p>

</body>

</html>
*********************************

Such is Life!
 
Old November 22nd, 2003, 11:49 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to acdsky
Default

I have found what I am looking for, below are some code that lookup folder and files and link them up to open.

Browse.asp
********************
<%@ Language=VBScript %>
<%
option explicit
dim sRoot, sDir, sParent, objFSO, objFolder, objFile, objSubFolder, sSize
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<title>Welcome</title>
</HEAD>
<BODY>

<%
' This is the root directory that the explorer will browse. Make sure there is no backslash ()
' at the end. Also make sure that show.asp has an identical sRoot variable.
sRoot = "c:\Inetpub\"

' Get the directory relative to the root directory
sDir = Request("Dir")

' Add a backslash
sDir = sDir & "\"

Response.Write "<h1>" & sDir & "</h1>" & vbCRLF

' Create a copy of FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
on error resume next
' Get a handle on the folder
Set objFolder = objFSO.GetFolder(sRoot & sDir)
if err.number <> 0 then
    Response.Write "Could not open folder"
    Response.End
end if
on error goto 0

' We want a link to the parent folder also
' Get the full path of the parent folder
sParent = objFSO.GetParentFolderName(objFolder.Path)

' Remove the contents of sRoot from the front. This gives us the parent
' path relative to the root folder
' eg. if parent folder is "c:webfilessubfolder1subfolder2" then we just want "subfolder1subfolder2"
sParent = mid(sParent, len(sRoot) + 1)

Response.Write "<table border=""1"">"

' Give a link to the parent folder. This is just a link to this page only pssing in
' the new folder as a parameter
Response.Write "<tr><td colspan=3><a href=""Browse.asp?dir=" & Server.URLEncode(sParent) & """>Return to Root</a></td></tr>" & vbCRLF

' Now we want to loop through the subfolders in this folder
For Each objSubFolder In objFolder.SubFolders
    ' And provide a link to them
    Response.Write "<tr><td colspan=3><a href=""Browse.asp?dir=" & Server.URLEncode(sDir & objSubFolder.Name) & """>" & objSubFolder.Name & "</a></td></tr>" & vbCRLF
Next

' Now we want to loop through the files in this folder
For Each objFile In objFolder.Files
    if Clng(objFile.Size) < 1024 then
        sSize = objFile.Size & " bytes"
    else
        sSize = Clng(objFile.Size / 1024) & " KB"
    end if
    ' And provide a link to view them. This is a link to show.asp passing in the directory and the file
    ' as parameters
    Response.Write "<tr><td><a href=""show.asp?file=" & server.URLEncode(objFile.Name) & "&dir=" & server.URLEncode (sDir) & """>" & objFile.Name & "</a></td><td>" & sSize & "</td><td>" & objFile.Type & "</td></tr>" & vbCRLF
Next

Response.Write "</table>"
%>

</BODY>
</HTML>
*****************************
Show.asp
*****************************
<%@ Language=VBScript %>
<%
option explicit
dim sFile, sRoot, sDir, sExt, objShell, objFSO, sMIME, objStream

' Author: Adrian Forbes -->

' Make sure this is the same sRoot variable that is defined in Internal_Browse
sRoot = "c:\Inetpub\"

' Get the directory relative to the root folder
sDir = Request("dir")

' Get the file we're going to show
sFile = Request("file")

' We need to know the MIME type for the file we are about to view. In
' order to get this we need to know the file's extension.
' We could use string functions to get the file extension but we've going
' to be lazy and use FileSystemObject
set objFSO = server.CreateObject("Scripting.FileSystemObject")
sExt = objFSO.GetExtensionName (sFile)
set objFSO = nothing

' Now we have the extension, the file's MIME type is held in the registry at
' HKEY_CLASSES_ROOT.<ext>Content Type
' Create an instance of Wscript.Shell to let us read the registry
Set objShell = Server.CreateObject("Wscript.Shell")
On Error Resume Next
' Get the MIME type
sMIME = objShell.RegRead("HKEY_CLASSES_ROOT." & sExt & "Content Type")
On Error GoTo 0
if len(sMIME) = 0 then
    ' If there is no registered type then return octetstream. This will prompt
    ' the user with the "Open or Save to disk" dialogue.
    sMIME = "application/octetstream"
end if
set objShell = nothing

' Tell the browse the content type
Response.ContentType = sMIME

' And the name of the file
Response.AddHeader "Content-Disposition", "filename=" & sFile & ";"

' Now we need to pipe the file to the browser, to do this we
' will use the ADODB.Stream
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
' Set the type as Binary
objStream.Type = 1
' Load our file
objStream.LoadFromFile sRoot & sDir & sFile

' And send it to the browser
Response.BinaryWrite objStream.Read

objStream.Close
Set objStream = Nothing
%>
*****************

Such is Life!





Similar Threads
Thread Thread Starter Forum Replies Last Post
lookup value in table Vince_421 Access 16 February 13th, 2007 08:15 AM
LookUp and Hyperlink frankjuel Excel VBA 1 January 12th, 2007 03:03 AM
lookup using VB karebear VB How-To 1 August 2nd, 2006 04:32 PM
lookup function Vince_421 Access VBA 14 May 19th, 2006 07:27 AM
Lookup Tables mossimo Access 4 December 5th, 2003 11:27 AM





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