October 19th, 2010, 02:39 PM
-
hey
Hey guys instead of lets say already knowing the file name can i some how display all the files in a folder "C:\Crap" and then the user would view all files and can then click and download there desired file.
October 20th, 2010, 04:27 AM
-
Originally Posted by Asp_Starter

Hey guys instead of lets say already knowing the file name can i some how display all the files in a folder "C:\Crap" and then the user would view all files and can then click and download there desired file.
Yes you can, but it got nothing to do with this thread.
One of the most simple codes to do this can be found here:
http://www.asp101.com/samples/dir_list.asp
October 20th, 2010, 08:02 AM
-
Virtual path required by map server. My physical path wont work ...
Hey well i gave it a shot.. and well this is the message i get
"The Path parameter for the MapPath method must be a virtual path. A physical path was used."
All i want is to make a page that i can view a folder in my c drive and let users download files from within that folder and so far i've tried at least 100times
, please help ...
Thanks.
This is the code :
<%
' I still like the idea of locking the script down somewhat
' so I've added the idea of a root path which is the level
' above which the script will not show folder contents.
Const strRootPath = "C:\"
Dim strThisPage ' This page's relative URL
Dim strPath ' Path of directory to show
Dim strFullPath ' strRootPath & strPath
Dim objFSO ' FileSystemObject
Dim objFolder ' Folder
Dim objItem ' Looping variable
' Set the URL of this script to a variable so we don't
' have to keep looking it up.
strThisPage = Request.ServerVariables("URL")
' Read the subfolder to show from the querystring.
strPath = Request.QueryString("Crap")
' Check to make sure no one is trying to escape our root path.
If InStr(1, strPath, ".", 1) <> 0 Then strPath = ""
If InStr(1, strPath, Server.URLEncode("."), 1) <> 0 Then strPath = ""
' Simply to save typing and computation later.
strFullPath = strRootPath & strPath
' Create our FSO and get a handle on our folder
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Server.MapPath(strFullPath))
' Show a description line and the title row of our table
%>
<p>
Contents of <strong><%= strFullPath %></strong>
</p>
<table border="1" cellspacing="0" cellpadding="2">
<tr>
<th>File Name:</th>
<th>File Size:</th>
<th>Date Created:</th>
<th>File Type:</th>
</tr>
<%
' First deal with any subdirectories. This is where the recursive
' script varies from the normal one. Take a look at how we build
' the link URLs.
' Show a link to the parent folder is applicable.
If strFullPath <> strRootPath Then
%>
<tr>
<td><a href="<%= strThisPage & "?path=" & Left(strPath, InStrRev(strPath, "/") - 1) %>">..</a></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<%
End If
' Show a link for each folder. The link calls this script again
' and passes it the path to the folder clicked upon.
For Each objItem In objFolder.SubFolders
' Deal with the stupid VTI's that keep giving our visitors 404's
If InStr(1, objItem, "_vti", 1) = 0 Then
%>
<tr>
<td><a href="<%= strThisPage & "?path=" & strPath & "/" & objItem.Name %>"><%= objItem.Name %></a></td>
<td align="right"><%= objItem.Size %></td>
<td><%= objItem.DateCreated %></td>
<td><%= objItem.Type %></td>
</tr>
<%
End If
Next 'objItem
' Now that I've done the SubFolders, do the files!
For Each objItem In objFolder.Files
%>
<tr>
<td><a href="<%= strFullPath & "/" & objItem.Name %>"><%= objItem.Name %></a></td>
<td align="right"><%= objItem.Size %></td>
<td><%= objItem.DateCreated %></td>
<td><%= objItem.Type %></td>
</TR>
<%
Next 'objItem
' All done! Kill off our object variables.
Set objItem = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
%>
</table>
April 4th, 2011, 07:03 PM
-
Originally Posted by Shadow Wizard
this is not something simple.
if you want permanent log of the downloads you'll have to use
database or text files. are you familiar with any of those?
did you try with different exe file? does it happen with other files?
try placing direct link to the file:
Code:
<a href="something.exe">download</a>
and try to download - can you activate the file after saving it?
Thanks for this code..it was help ful...but is there a way to get dynamic files rather than already set ?
April 5th, 2011, 03:26 AM
-
Originally Posted by walataza
Thanks for this code..it was help ful...but is there a way to get dynamic files rather than already set ?
What do you mean "dynamic files"? Can you please explain/elaborate?
August 18th, 2011, 05:15 PM
-
Files automatically open in IE
Hello,
Your code works awesome. However, whenever I download any file in firefox, it automatically tries to open it in ie even though the file may be a word document or an executable. This does not happen in IE or Chrome. Any help would be greatly appreciated.
Thanks.
August 19th, 2011, 06:56 PM
-
You might want to check your file associations and see whats happening in there..
Comments on this post
Life is Good
October 13th, 2011, 05:04 PM
-
Originally Posted by Deri6ck78
it works great for showing the file but when I try it with forcedownload=true it just shows garbage on the browser and I don't get any save to disk option.
Sorry I don't help spammers. Bye!
January 20th, 2012, 05:08 AM
-
Script not working on 2008 r2 IIS
I have copied over a site from Server 2008 32 bit to Server 2008 R2 iis and everything seems to working ASP and SQL wise.
However, I cannot seem to get the links to download any files working.
If I change my hyperlink files names to .txt text files it finds the files and comes up with the OPEN, SAVE, CANCEL dialog. However, when i try and download exiting files (pdf, doc) etc all i get is the website could not display the page.
Am i missing something?!
Been trying for ages to get this working but cant.
Please help!
Thanks.
Last edited by Shadow Wizard; January 22nd, 2012 at 02:45 AM.
January 22nd, 2012, 02:47 AM
-
Originally Posted by martin182003
I have copied over a site from Server 2008 32 bit to Server 2008 R2 iis and everything seems to working ASP and SQL wise.
However, I cannot seem to get the links to download any files working.
If I change my hyperlink files names to .txt text files it finds the files and comes up with the OPEN, SAVE, CANCEL dialog. However, when i try and download exiting files (pdf, doc) etc all i get is the website could not display the page.
Am i missing something?!
Been trying for ages to get this working but cant.
Please help!
Thanks.
If you copy such file to the website root and put ordinary link (<a href="myfile.pdf">myfile</a>) - does this work? I suspect that even this will give you same error.
January 22nd, 2012, 04:40 AM
-
Hi
I have already tried that and it works fine..which doesnt make any sense to me why it doesnt work with the same file in the secure folder, yet it works with .txt files.
Originally Posted by Shadow Wizard
If you copy such file to the website root and put ordinary link (<a href="myfile.pdf">myfile</a>) - does this work? I suspect that even this will give you same error.
January 22nd, 2012, 05:15 AM
-
Originally Posted by martin182003
Hi
I have already tried that and it works fine..which doesnt make any sense to me why it doesnt work with the same file in the secure folder, yet it works with .txt files.
Hmm.. try to disable friendly errors:
IE Tools --> Internet Options --> Advanced --> uncheck "show friendly HTTP error messages" and Apply.
You should now see full error message, post it here and I'll have a lead.
January 22nd, 2012, 05:21 AM
-
I tried that aswell, but it still just comes up with Internet Explorer cannot display the webpage. If I point to a text file within the same secure folder, it works!
I have also set IIS to send errors to browser as TRUE but this has made no difference either.
Have cross checked all settings with current working server and everything is the same!!
Originally Posted by Shadow Wizard
Hmm.. try to disable friendly errors:
IE Tools --> Internet Options --> Advanced --> uncheck "show friendly HTTP error messages" and Apply.
You should now see full error message, post it here and I'll have a lead.
January 22nd, 2012, 05:30 AM
-
Here's one for you.
In the foler with the pdf that doesnt work, I created a test.txt file and then in the webpage I ujust changed the file name in the address bar..
and in the saveAS box it comes up with Name: _nrg_pay_test.txt
The URL is file=nrg/pay/test.txt
A problem with slashes being replaced with underscores anything to do with it?
The text file obviously opens somehow, as I get the option to open, save or cancel!
Originally Posted by martin182003
I tried that aswell, but it still just comes up with Internet Explorer cannot display the webpage. If I point to a text file within the same secure folder, it works!
I have also set IIS to send errors to browser as TRUE but this has made no difference either.
Have cross checked all settings with current working server and everything is the same!!
January 22nd, 2012, 05:51 AM
-
Originally Posted by martin182003
In the foler with the pdf that doesnt work, I created a test.txt file and then in the webpage I ujust changed the file name in the address bar..
and in the saveAS box it comes up with Name: _nrg_pay_test.txt
The URL is file=nrg/pay/test.txt
A problem with slashes being replaced with underscores anything to do with it?
No, this is browser behavior to avoid having invalid file name.
Originally Posted by martin182003
The text file obviously opens somehow, as I get the option to open, save or cancel!
Click "open" you might see some useful error message - in such case, post it here.
Anyway, try to remove this line from the code:
Code:
Response.AddHeader "Content-Disposition", "attachment; filename="&strFileName
Any change?