Solved

ASP Button to Access File

Posted on 2014-04-26
16
455 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
[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
  • 8
  • 6
  • 2
16 Comments
 
LVL 53

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 33

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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 33

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 33

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 33

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 53

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 33

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 33

Expert Comment

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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.
This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

737 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