Solved

ASP Page shows all files need to exclude files Help

Posted on 2013-12-06
12
488 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

 
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

717 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