Solved

ASP Page shows all files need to exclude files Help

Posted on 2013-12-06
12
479 Views
Last Modified: 2013-12-11
Windows 2003 IIS 6 Web server

The below code works http://localhost/music_9.asp

Displays a full list of the contents of the mp3 music albums folder.

1. Would like the list to only show .mp3 and .m4a files
2. When the list is presented can a button be placed next to the file that one could click and then it will play that mp3 or m4a file


<% ListFolderContents(Server.MapPath("/mp3/mp3 music albums")) %>
<% 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("<h2>"& folder.Name &"</h2>")

     'Display a list of sub folders.

     for each item in folder.SubFolders
                ListFolderContents(item.Path)
     next

     'Display a list of files.
Response.Write("<ul>")
    for each item in folder.Files
       url = MapURL(item.path)
        Response.Write("<li><a href=""" & url & """>" & item.Name & "</a></li>")
    next
        Response.Write("</ul>")
   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 %>


Looking to display all mp3/m4a files and then one can play any song by clicking on it

Any ideas Thanks
Tom
0
Comment
Question by:Thomas Grassi
  • 6
  • 6
12 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39701699
I dont' think you need a button.  I think they will play in whatever application the user has assigned to that extension.
0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 39701724
Dave

when I click on the file it comes back with http 404 page can not be found

http://www.tgcsnet.com/music_9.asp

check it out

IUSR has Read & Execute, List Contents, and Read permissions on that folder.

Also want to only list .mps and .m4a can that be done with the code I have?
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39701783
There is something wrong with the way you are creating the URLs.  When I go directly to this song URL, it plays fine.
http://www.tgcsnet.com/mp3/MP3%20Music%20Albums/Deep%20Purple/Machine%20Head/01%20-%20Highway%20Star%20%28LP%20Version%29.mp3

The first thing I suggest is getting rid of the spaces in the directory names.  Or at least converting them to underscores '_'.  You may find that the parsing of the folder names is failing because of the spaces.  I also don't see the main directory http://www.tgcsnet.com/mp3 in your URLs either.
0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 39701830
Yes that works that way so what is wrong with the way the url is being created?

code:

<% ListFolderContents(Server.MapPath("/mp3/mp3 music albums")) %>
<% 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("<h2>"& folder.Name &"</h2>")

     'Display a list of sub folders.

     for each item in folder.SubFolders
                ListFolderContents(item.Path)
     next

     'Display a list of files.
Response.Write("<ul>")
    for each item in folder.Files
       url = MapURL(item.path)
        Response.Write("<li><a href=""" & url & """>" & item.Name & "</a></li>")
    next
        Response.Write("</ul>")
   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 %>


This is what is being created

http://www.tgcsnet.com/Albums/Deep%20Purple/Machine%20Head/01%20-%20Highway%20Star%20(LP%20Version).mp3


vs what works

http://www.tgcsnet.com/mp3/MP3%20Music%20Albums/Deep%20Purple/Machine%20Head/01%20-%20Highway%20Star%20%28LP%20Version%29.mp3 


I see a big difference but not sure what to change?

I am new to this type of coding...
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 39702017
I would remove the spaces in the folder names first and make sure that the case is the same everywhere you use it.  Like this:

/mp3/MP3MusicAlbums
0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 39702029
Dave

Yes I was thinking that two

I will make that change tonight and test

Any thoughts about how I can only display .MP3 and .M4A and WMA files
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39702184
Not until it actually works.
0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 39702371
Dave,

Made the change still does not work I think it is the code? Need your help on that please.

Now it looks like this

http://www.tgcsnet.com/lbums/Deep%20Purple/Machine%20Head/01%20-%20Highway%20Star%20(LP%20Version).mp3



Code:

code:

<% ListFolderContents(Server.MapPath("/mp3/mp3musicalbums")) %>
<% 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("<h2>"& folder.Name &"</h2>")

     'Display a list of sub folders.

     for each item in folder.SubFolders
                ListFolderContents(item.Path)
     next

     'Display a list of files.
Response.Write("<ul>")
    for each item in folder.Files
       url = MapURL(item.path)
        Response.Write("<li><a href=""" & url & """>" & item.Name & "</a></li>")
    next
        Response.Write("</ul>")
   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 %>

I restarted IIS just to make sure the changes to the alias was made

Still does not work

Any ideas

 Thanks
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39702542
0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 39706088
Dave

any time to look at the code today?

It is something in my code that is causing this?

My ASP code knowledge is ok but by no means expert level.

Any help would be great.
0
 
LVL 23

Author Closing Comment

by:Thomas Grassi
ID: 39711168
Dave

Got it working

Going to post another question about how to only show .mp3 .m4a and .wma files.

Thanks for your help
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39712060
You're welcome, glad to help.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now