Solved

ASP Button to Access File

Posted on 2014-04-26
16
449 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 52

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 32

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

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 32

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 32

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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 52

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 32

Accepted Solution

by:
Big Monty earned 500 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 32

Expert Comment

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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Problem to be resolved in this article Currently, development of website and web application can be done without writing thousands of lines of programming code by hand. Description This can be done through by using a open source framework such …
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

708 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

13 Experts available now in Live!

Get 1:1 Help Now