display folder contents + specific text for a particular file type

This is a discussion on "display folder contents + specific text for a particular file type" within the Classic ASP section. This forum, and the thread "display folder contents + specific text for a particular file type are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Aug 14th, 2006, 21:57
New Member
Join Date: Aug 2006
Location: New Zealand
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
display folder contents + specific text for a particular file type

Hi am creating a site that when a menu item is clicked it displays the contents of a specific folder - PDFs, PPT documents etc....

It lists the file type icon, name of the file, size and date last modified. What I want to do is add "right click - save link as" after the date, but only to PowerPoint documents.

Any help with this would be greatly appreciated.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Aug 17th, 2006, 13:02
New Member
Join Date: Aug 2006
Location: Birmingham, UK
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Re: display folder contents + specific text for a particular file type

Hi magnum.

The easiest thing to do is look at the last 4 characters of each file's name (your best bet is to turn the filename into lowercase first). If the file ends in ".ppt", your write the specified text.

The example I use below assumes each file's details are stored in a database. I can supply you a more relevant example if you'd like to supply the code you're using.

Code: Select all
<table>
    <tr>
        <th>Filename</th>
        <th>Size</th>
        <th>Last Modified</th>
        <th>Download</th>
    </tr>
 
    <% Do Until recordset.EOF 'Loop through each record %>
    <tr>
        <td><%=recordset("Filename")%></td>
        <td><%=recordset("FileSize")%></td>
        <td><%=formatDate(recordset("dateMofieid"), "dd/MM/yyyy")%></td>
        <td>
            <%
                Dim strFilename
               Dim strExt
 
               strFilename = LCase(recordset("Filename"))
               strExt = Right(strFilename, 4)
 
               If strExt = ".ppt" Then
                   Response.Write("Right click - save link as")
               Else
                   Response.Write("Click filename to download")
               End If
           %>
        </td>
    </tr>
    <%
        recordset.MoveNext()
        Loop
    %>
</table>
That big script block is the one to concentrate on. Here it declares two variables, one to store the filename, the other to store the file extension.

The LCase function returns a string in lower case, so it'll turn "PowerPointFile.PPT" into "powerpointfile.ppt". This value is then loaded into the strFilename variable.

The Right function returns the right-hand portion of a string (in this case strFilename). The number 4 means that the function must return the last four characters of the filename (we're looking for ".ppt").

We then use a simple If...Then...Else statement, using Response.Write to write the appropriate text toto the page.

The reason we need to want to include the dot (.) in the extension is so that we know those last four letters are the extension for the file, and not part of the main body of the filename.

Hope that's of some use. If not, or if the example isn't relevant, pass me the page you're working on and I'll take a look.

Kind regards,
-Mark

View my web development blog

Last edited by elopus; Aug 17th, 2006 at 13:05. Reason: Had to remove bold formatting in CODE block, as it removed my line-breaks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
display, folder, contents, specific, text, particular, file, type

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multi file uploader and folder create 737mechanic PHP Forum 1 Sep 29th, 2007 11:03
Using type 'Text' everywhere, wrong? @lun Databases 1 Aug 8th, 2007 18:46
Can I put style sheet in the root folder that targets a specific html page badger Web Page Design 3 Jul 14th, 2007 17:35
script to list folder contents as links taras JavaScript Forum 0 May 26th, 2007 09:59
Folder and file management pengyou Starting Out 4 May 23rd, 2007 08:23


All times are GMT. The time now is 14:04.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42