#61
  1. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Oct 2010
    Posts
    6
    Rep Power
    0

    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.
  2. #62
  3. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2926
    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
  4. #63
  5. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Oct 2010
    Posts
    6
    Rep Power
    0

    Unhappy 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>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</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>
  6. #64
  7. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Mar 2010
    Posts
    24
    Rep Power
    0
    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 ?
  8. #65
  9. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2926
    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?
  10. #66
  11. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Aug 2011
    Posts
    1
    Rep Power
    0

    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.
  12. #67
  13. No Profile Picture
    Help and be helped
    ASP Adventurer (500 - 999 posts)

    Join Date
    Feb 2004
    Location
    Australia
    Posts
    584
    Rep Power
    127
    You might want to check your file associations and see whats happening in there..

    Comments on this post

    • Shadow Wizard agrees
    Life is Good
  14. #68
  15. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2926
    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!
  16. #69
  17. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jan 2012
    Posts
    7
    Rep Power
    0

    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.
  18. #70
  19. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2926
    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.
  20. #71
  21. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jan 2012
    Posts
    7
    Rep Power
    0
    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.
  22. #72
  23. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2926
    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.
  24. #73
  25. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jan 2012
    Posts
    7
    Rep Power
    0
    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.
  26. #74
  27. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jan 2012
    Posts
    7
    Rep Power
    0
    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!!
  28. #75
  29. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2926
    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?

Similar Threads

  1. File Download problems
    By clboren in forum ASP Development
    Replies: 0
    Last Post: March 15th, 2005, 04:54 PM
  2. Issue downloading large files
    By Ceuphrasie in forum ASP Development
    Replies: 13
    Last Post: March 14th, 2005, 10:33 AM
  3. Download Two Files From One Button?
    By Currie in forum .NET Development
    Replies: 1
    Last Post: February 5th, 2005, 03:56 AM
  4. Downloading files
    By Zil in forum .NET Development
    Replies: 7
    Last Post: January 8th, 2005, 08:23 AM
  5. FTP download a number of files with same extension
    By otarboy in forum Visual Basic Programming
    Replies: 1
    Last Post: September 29th, 2004, 11:27 AM

IMN logo majestic logo threadwatch logo seochat tools logo