Member_2_6492660_1
asked on
My ASP coded Web PAge is Building incorrect URL HyperLinks
Windows 2003 Server IIS6 ASP and ASP.NET
The code below works presents a web page that lists all the files in the mappath statement.
My problem is that the code is building an incorrect URL statement for each file.
So when someone clicks on the filename they get Error 404 page not found
This works... typed in manually
http://www.tgcsnet.com/mp3/MP3MusicAlbums/Deep%20Purple/Machine%20Head/01%20-%20Highway%20Star%20%28LP%20Version%29.mp3
This is what is being built by my code.
http://www.tgcsnet.com/lbums/Deep%20Purple/Machine%20Head/01%20-%20Highway%20Star%20(LP%20Version).mp3
I by no means is an expert in ASP coding can use all the help I can get.
The code below works presents a web page that lists all the files in the mappath statement.
My problem is that the code is building an incorrect URL statement for each file.
So when someone clicks on the filename they get Error 404 page not found
This works... typed in manually
http://www.tgcsnet.com/mp3/MP3MusicAlbums/Deep%20Purple/Machine%20Head/01%20-%20Highway%20Star%20%28LP%20Version%29.mp3
This is what is being built by my code.
http://www.tgcsnet.com/lbums/Deep%20Purple/Machine%20Head/01%20-%20Highway%20Star%20(LP%20Version).mp3
I by no means is an expert in ASP coding can use all the help I can get.
<% 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 %>
ASKER
thanks for responding
No my MP3 files are not in the same folder
I have hundreds of folders and sub folders.
As I said above I am not an expert on ASP code.
Any ideas on what is wrong can you provide me a correction to my code?
Thanks
No my MP3 files are not in the same folder
I have hundreds of folders and sub folders.
As I said above I am not an expert on ASP code.
Any ideas on what is wrong can you provide me a correction to my code?
Thanks
Hi,
the problem is that your function MapURL will probably always return the wrong shortened string.
Can you perhaps provide the info:
Where is your root folder of the web site (the full physical path)?
Where is your MP3 root folder (full physical path)?
You call the first function with
using the substring RIGHT function which is causing this issue.
the problem is that your function MapURL will probably always return the wrong shortened string.
Can you perhaps provide the info:
Where is your root folder of the web site (the full physical path)?
Where is your MP3 root folder (full physical path)?
You call the first function with
Server.MapPath("/mp3/mp3 music albums")
but then inside the mapUrl function you useServer.MapPath("/")
using the substring RIGHT function which is causing this issue.
See if this works
<% sub ListFolderContents(path)
'***********************************************
' At this point, we know the path, we just need the file names in the 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) **** take this line out and take out "url" below and use "path"
Response.Write("<li><a href=""" & path & """>" & item.Name & "</a></li>")
next
Response.Write("</ul>")
end sub
%>
ASKER
Rainerj:
My Root Site this is where music_9.asp resides
c:\inetpub\wwwroot
My MP3 files reside here
F:\music\mp3musicalbums
I created an alias in IIS named MP3 that's why my mappath is /mp3/mpsmusic/albums.
My Root Site this is where music_9.asp resides
c:\inetpub\wwwroot
My MP3 files reside here
F:\music\mp3musicalbums
I created an alias in IIS named MP3 that's why my mappath is /mp3/mpsmusic/albums.
ASKER
Padas
tried your code got a blank page.
did not find any files
is this complete code or do I need to replace some of mine?
tried your code got a blank page.
did not find any files
is this complete code or do I need to replace some of mine?
Can you use mappath outside of the site? I think you may need to use something like "F:\music\mp3musicalbums\" &path
ASKER
Padas
check it out
http://www.tgcsnet.com/music_15.asp
it changed the url to file:///.................. .......
When you click on the name it does not do any thing.
I added the
<% ListFolderContents(Server. MapPath("/ mp3/mp3mus icalbums") ) %>
to your code example
The idea here is to click on the file and play the song.
I do not think I can access them using F:\music\mp3musicalbums
Example please
<% ListFolderContents(Server.MapPath("/mp3/mp3musicalbums")) %>
<% sub ListFolderContents(path)
'***********************************************
' At this point, we know the path, we just need the file names in the 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) **** take this line out and take out "url" below and use "path"
Response.Write("<li><a href=""" & path & """>" & item.Name & "</a></li>")
next
Response.Write("</ul>")
end sub
%>
check it out
http://www.tgcsnet.com/music_15.asp
it changed the url to file:///..................
When you click on the name it does not do any thing.
I added the
<% ListFolderContents(Server.
to your code example
The idea here is to click on the file and play the song.
I do not think I can access them using F:\music\mp3musicalbums
Example please
ASKER
Rainerj:
Do not understand your last comment?
Did you mean to post new code?
Did you see my response to you I answered your questions?
Any ideas how I can get this to work so close...
Do not understand your last comment?
Did you mean to post new code?
Did you see my response to you I answered your questions?
Any ideas how I can get this to work so close...
Hi,
could you try this?
could you try this?
<% 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) - 5)
MapURL = Replace(url, "\", "/")
end function %>
ASKER
Rainerj.
Ok thanks I need to know how to do that for future postings.
I tested your code we are real close now
here is what is built
http://www.tgcsnet.com/sic/MP3MusicAlbums/Deep%20Purple/Machine%20Head/01%20-%20Highway%20Star%20(LP%20Version).mp3
SIC ???? needs to be mp3
Ok thanks I need to know how to do that for future postings.
I tested your code we are real close now
here is what is built
http://www.tgcsnet.com/sic/MP3MusicAlbums/Deep%20Purple/Machine%20Head/01%20-%20Highway%20Star%20(LP%20Version).mp3
SIC ???? needs to be mp3
Hi,
sorry I have no IIS6 server at hand, therefore could you please try this:
HTH
Rainer
sorry I have no IIS6 server at hand, therefore could you please try this:
<% 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("/")
Response.Write("<li>Rootpath: -" & rootPath & "- | path: -"& path & "-</li>")
url = Right(path, Len(path) - 5)
MapURL = Replace(url, "\", "/")
end function %>
This will dump the two important variables and then we should be able to get an idea about where and how this paths come from.HTH
Rainer
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Rainerj:
Thanks that works.
Is there anyway I can stop someone from download the file?
I just want them to be able to play the song not download it
Thanks that works.
Is there anyway I can stop someone from download the file?
I just want them to be able to play the song not download it
Hi,
afaik this would not be that easy (if not even impossible). You would need some kind of streaming server and even with that there are tools/programs available to save the streams.
HTH
Rainer
afaik this would not be that easy (if not even impossible). You would need some kind of streaming server and even with that there are tools/programs available to save the streams.
HTH
Rainer
ASKER
Raier
Ok sounds like a lot of work in that
was just wondering how amazon and others do that.
Will look into that in the future.
One more question for you.
Is there a way to only display .mp3 .m4a and .wma file types?
don't really need to display the art work and other files in this listing?
Ok sounds like a lot of work in that
was just wondering how amazon and others do that.
Will look into that in the future.
One more question for you.
Is there a way to only display .mp3 .m4a and .wma file types?
don't really need to display the art work and other files in this listing?
ASKER
worked great
now onto tweaking
now onto tweaking
Open in new window
Can you see your function where you are taking the right(path,len(path)-len(r
Open in new window
If all mp3's are in the same folder, just use the actual location and file name. It seems like MapPath is throwing you off.