• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 649
  • Last Modified:

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.


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

Open in new window

0
Thomas Grassi
Asked:
Thomas Grassi
  • 10
  • 5
  • 3
1 Solution
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Making this readable

http://www.tgcsnet.com/mp3/MP3MusicAlbums/Deep Purple/Machine Head/01 - Highway Star (LP Versionz).mp3
http://www.tgcsnet.com/lbums/Deep Purple/Machine Head/01 - Highway Star (LP Version).mp3

Open in new window


Can you see your function where you are taking the right(path,len(path)-len(rootPath)) is probably throwing this off

http://www.tgcsnet.com/mp3/MP3MusicAlbums/Deep Purple/Machine Head/01 - Highway Star (LP Versionz).mp3
http://www.tgcsnet.com/              lbums/Deep Purple/Machine Head/01 - Highway Star (LP Version).mp3

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.
0
 
Thomas GrassiSystems AdministratorAuthor Commented:
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
0
 
Rainer JeschorCommented:
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
Server.MapPath("/mp3/mp3 music albums")

Open in new window

but then inside the mapUrl function you use
Server.MapPath("/")

Open in new window


using the substring RIGHT function which is causing this issue.
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
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
  %>

Open in new window

0
 
Thomas GrassiSystems AdministratorAuthor Commented:
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.
0
 
Thomas GrassiSystems AdministratorAuthor Commented:
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?
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Can you use mappath outside of the site?  I think you may need to use something like  "F:\music\mp3musicalbums\"&path
0
 
Thomas GrassiSystems AdministratorAuthor Commented:
Padas

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

Open in new window


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/mp3musicalbums")) %>
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
0
 
Thomas GrassiSystems AdministratorAuthor Commented:
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...
0
 
Rainer JeschorCommented:
Hi,

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

Open in new window

0
 
Thomas GrassiSystems AdministratorAuthor Commented:
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
0
 
Rainer JeschorCommented:
Hi,

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

Open in new window

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
0
 
Thomas GrassiSystems AdministratorAuthor Commented:
Rainer,

ok done  check this out

http://www.tgcsnet.com/music_17.asp
0
 
Rainer JeschorCommented:
Hi,
then this should do the trick:
<% 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.
     url = "/mp3/" & Right(path, Len(path) - 9)
     MapURL = Replace(url, "\", "/")
end function  %>

Open in new window

0
 
Thomas GrassiSystems AdministratorAuthor Commented:
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
0
 
Rainer JeschorCommented:
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
0
 
Thomas GrassiSystems AdministratorAuthor Commented:
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?
0
 
Thomas GrassiSystems AdministratorAuthor Commented:
worked great

now onto tweaking
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

  • 10
  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now