?
Solved

ASP Button to Access File

Posted on 2014-04-26
16
Medium Priority
?
463 Views
Last Modified: 2014-04-27
IIS 6.0
ASP Classic
SQL 2008

I have a web site I am working on that I need a Button to open a file

The code below create a file M:\Playlist\MyPlayList_########.M3U

The ####### = Session.SessionID

the Button named PlayList is what I need help on

When a user click on PlayList button needs to double click on that file to launch it via a Href  then the songs in the playlist should start playing.

<%
if request.form<>"" then
dim fs,fname
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fname=fs.CreateTextFile("m:\playlist\myplaylist_"&Session.SessionID&".txt",true)
strSongs=request.form("selectItem")
arraySongs=split(strSongs,",")
response.write "<ul>"
for each song in arraySongs
   response.write "<li><a href=""" & replace(song,"M:\Music","/mp3") & """>" & song & "</a></li>" 
   
   fname.WriteLine "<a href=""" &server.URLEncode(replace(song,"M:\Music","/mp3")) & """>" & song & "</a>"   
   
   next
response.write "</ul>" 
fname.Close
else
response.write "You did not post any data yet<br>"
end if
set fname=nothing
set fs=nothing
%>
<input type="button" value="BACK!"onClick="history.back();">
<input type="button" value="PlayList"onClick="history.back();">

Open in new window

0
Comment
Question by:Thomas Grassi
  • 8
  • 6
  • 2
16 Comments
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 40025283
At this point, you have your m3u file.  You need more than a button to get it to play...

From my understanding, the m3u is just a playlist.  Wouldn't it be easier to use the html5 audio tag? https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio
<audio src="foo.ogg">
  <track kind="captions" src="foo.en.vtt" srclang="en" label="English">
  <track kind="captions" src="foo.sv.vtt" srclang="sv" label="Svenska">
</audio>

Open in new window


Or use a player
https://flowplayer.org/docs/playlist.html (h5ml5)
http://flash.flowplayer.org/plugins/streaming/audio.html (flash)

or jplayer http://jplayer.org/

Looking at flowplayer http://flash.flowplayer.org/documentation/configuration/playlists.html

This bit of code
response.write "<ul>"
for each song in arraySongs
   response.write "<li><a href=""" & replace(song,"M:\Music","/mp3") & """>" & song & "</a></li>" 
   
   fname.WriteLine "<a href=""" &server.URLEncode(replace(song,"M:\Music","/mp3")) & """>" & song & "</a>"   
   
   next
response.write "</ul>" 

Open in new window

Could be
<%
dim playlist
playlist=""
for each song in arraySongs
    playlist=playlist&"'"&replace(song,"M:\Music","/mp3")&"',"
next
playlist=left(playlist,len(playlist)-1) ' take out last comma
%>

<script>
flowplayer("containerId", "flowplayer-3.2.18.swf", {
    // playlist with two video clips
    playlist: [ <%=playlist%>]
});
</script>

Open in new window


I would try hardcoding first.  Have you been able to play your list manually as it is?
0
 
LVL 34

Expert Comment

by:Big Monty
ID: 40025639
If you're expecting your users to play the songs through their own players and you just want to open the file,  then you should be able to do something like:

 <button value="Playlist" onclick="window.location = '<%=pathToPlayList%>'" > Playlist <button>

Try hard coding a path for the pathToPlayList variable and see if that works
0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40025778
Big Monty

Yes that exactly what I am looking for

I hard coded the path but it did not like what I typed

Microsoft VBScript compilation  error '800a0400'

Expected statement

/music3.asp, line 24
M:\Playlist\myplaylist.m3u
--^

My code:

<%
if request.form<>"" then
dim fs,fname
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fname=fs.CreateTextFile("m:\playlist\myplaylist_"&Session.SessionID&".txt",true)
strSongs=request.form("selectItem")
arraySongs=split(strSongs,",")
response.write "<ul>"
for each song in arraySongs
   response.write "<li><a href=""" & replace(song,"M:\Music","/mp3") & """>" & song & "</a></li>" 
   
   fname.WriteLine "<a href=""" &server.URLEncode(replace(song,"M:\Music","/mp3")) & """>" & song & "</a>"   
   
   next
response.write "</ul>" 
fname.Close
else
response.write "You did not post any data yet<br>"
end if
set fname=nothing
set fs=nothing
%>
<input type="button" value="BACK!"onClick="history.back();">
<button value="Playlist" onclick="window.location = '<%M:\Playlist\myplaylist.m3u%>'" > Playlist <button>

Open in new window

0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 34

Expert Comment

by:Big Monty
ID: 40025783
Try this
<button value="Playlist" onclick="window.location = '<%=Server.UrlEncode ( "M:\Playlist\myplaylist.m3u" )%>'" > Playlist </button>
0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40025799
Big Monty:

Thanks we are getting close

404 Error File or Directory not Found

this is the URL generated    http://www.tomsmp3.com/M%3A%5CPlaylist%5Cmyplaylist.m3u

My code now:

<%
if request.form<>"" then
dim fs,fname
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fname=fs.CreateTextFile("m:\playlist\myplaylist_"&Session.SessionID&".txt",true)
strSongs=request.form("selectItem")
arraySongs=split(strSongs,",")
response.write "<ul>"
for each song in arraySongs
   response.write "<li><a href=""" & replace(song,"M:\Music","/mp3") & """>" & song & "</a></li>" 
   
   fname.WriteLine "<a href=""" &server.URLEncode(replace(song,"M:\Music","/mp3")) & """>" & song & "</a>"   
   
   next
response.write "</ul>" 
fname.Close
else
response.write "You did not post any data yet<br>"
end if
set fname=nothing
set fs=nothing
%>
<input type="button" value="BACK!"onClick="history.back();">
<button value="Playlist" onclick="window.location = '<%=Server.UrlEncode ( "M:\Playlist\myplaylist.m3u" )%>'" > Playlist </button>

Open in new window

0
 
LVL 34

Expert Comment

by:Big Monty
ID: 40025822
Sorry I haven't slept all night,  my girlfriends sis just had a baby ;)

Change
Server.UrlEncode
To
Server.MapPath
0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40025843
Big Monty

That's
Great News

After making the above change getting this now  See attached file image
ASP-Error.bmp
0
 
LVL 34

Expert Comment

by:Big Monty
ID: 40025899
Thx!

I recall you using a function in one of your other questions to convert your path to a virtual one. Replace server.mappath with that function
0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40025917
Big Monty

Get some rest

Lets work on this later.

Been looking at IIS and not sure if I am missing something there

IIS 6.0 I just enabled Parent Paths  but no luck
0
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 40025964
Do not enable parent paths.  That is a security risk.  Just avoid using relative paths.
0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40025992
Scott

thanks for chiming in

I already removed it the change did not make it work.

Here is my current code.

<%
if request.form<>"" then
dim fs,fname
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fname=fs.CreateTextFile("m:\playlist\myplaylist_"&Session.SessionID&".txt",true)
strSongs=request.form("selectItem")
arraySongs=split(strSongs,",")
response.write "<ul>"
for each song in arraySongs
   response.write "<li><a href=""" & replace(song,"M:\Music","/mp3") & """>" & song & "</a></li>" 
   
   fname.WriteLine "<a href=""" &server.URLEncode(replace(song,"M:\Music","/mp3")) & """>" & song & "</a>"   
   
   next
response.write "</ul>" 
fname.Close
else
response.write "You did not post any data yet<br>"
end if
set fname=nothing
set fs=nothing
%>
<input type="button" value="BACK!"onClick="history.back();">
<button value="Playlist" onclick="window.location = '<%=Server.MapPath ( "M:/Playlist/myplaylist.m3u" )%>'"> Playlist </button>

Open in new window


Still getting invalid path see attached image above ID: 40025843

Thanks
0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40026030
Update

New code no error now but the Playlist button does not function you click on it and nothing happens

See new code

<%
if request.form<>"" then
dim fs,fname
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fname=fs.CreateTextFile("m:\playlist\myplaylist_"&Session.SessionID&".txt",true)
strSongs=request.form("selectItem")
arraySongs=split(strSongs,",")
response.write "<ul>"
for each song in arraySongs
   response.write "<li><a href=""" & replace(song,"M:\Music","/mp3") & """>" & song & "</a></li>" 
   
   fname.WriteLine "<a href=""" &server.URLEncode(replace(song,"M:\Music","/mp3")) & """>" & song & "</a>"   
   next
response.write "</ul>" 
fname.Close
else
response.write "You did not post any data yet<br>"
end if
set fname=nothing
set fs=nothing
%>
<input type="button" value="BACK!"onClick="history.back();">
<button value="Playlist" onclick="window.location = '<%=Server.MapPath ( "Playlist/myplaylist.m3u" )%>'" > Playlist </button>

Open in new window




Also I manually entered into a url  this

http://www.tomsmp3.com/%3A%5CPlaylist%5Cmyplaylist.m3u

It worked.

So now all I need is to get the Button to do this which I think it is since I removed the M:\ from the MapPath See code above.
0
 
LVL 34

Accepted Solution

by:
Big Monty earned 2000 total points
ID: 40026121
ok, let's try this code (now that I've had 2 hours to sleep!)

<button value="Playlist" onclick="window.location = '<%="/Playlist/myplaylist.m3u"%>'"> Playlist </button>

You shouldn't need any kind of url encoding (which was being done by the function Server.URLEncode) unless you have special characters in your path (including spaces).

My apologies for confusing you with the Server.MapPath function, as I was trying to pass time in the hospital on here answering questions after having been up 24+ hours straight :) That function will convert a relative path to a physical one, and not vice versa (which is what you needed
0
 
LVL 23

Author Closing Comment

by:Thomas Grassi
ID: 40026130
Big Monty

Totally understandable Glad you got some sleep to clear your head.

Now working thanks to all
0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40026131
big Monty.

One quick question

<button value="Playlist" onclick="window.location = '<%="/Playlist/myplaylist.m3u"%>'"> Playlist </button>

Proper syntax to add the session.sessionid in the file name

<button value="Playlist" onclick="window.location = '<%="/Playlist/myplaylist_"&Session.SessionID&".m3u"%>'"> Playlist </button>


How does the above look
0
 
LVL 34

Expert Comment

by:Big Monty
ID: 40026216
syntactically that looks correct
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
This video teaches users how to migrate an existing Wordpress website to a new domain.
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…
Suggested Courses
Course of the Month17 days, 4 hours left to enroll

862 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