Solved

ASP Page shows all files need to exclude files Help

Posted on 2013-12-06
12
473 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 82

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 82

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 82

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 82

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 82

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 82

Expert Comment

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

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

744 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

12 Experts available now in Live!

Get 1:1 Help Now