Solved

ASP Page shows all files need to exclude files Help

Posted on 2013-12-06
12
484 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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
 
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Is there any way to limit concurrent connection in IIS7? 6 39
QQ problem 22 43
Random port 80 connection refuse flapping 14 32
PHP 5.6 and 7.x 4 23
A phishing scam that claims a recipient’s credit card details have been “suspended” is the latest trend in spoof emails.
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
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.

828 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