?
Solved

ASP Button to Access File

Posted on 2014-04-26
16
Medium Priority
?
459 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 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 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
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

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

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 33

Expert Comment

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

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
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.

650 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