Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Forcing a download

Forcing a download

Scheduled Pinned Locked Moved Web Development
tutorialannouncement
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DFU23
    wrote on last edited by
    #1

    I'm looking for info on how to make any file (.pdf, .jpg, .doc, .anything) forced as a download even if the browser (mainly IE) thinks it knows what to do with that kind of file. For example: I have a series of links, I want the user to only have to left click to initiate the download. If they click on a .jpg file it will try to open it in the browser and just show the image. I want it to prompt a user for downoad regarless of file type. I am using ASP to develop this project currently. TIA,

    Wally Atkins
    Newport News, VA, USA

    D 1 Reply Last reply
    0
    • D DFU23

      I'm looking for info on how to make any file (.pdf, .jpg, .doc, .anything) forced as a download even if the browser (mainly IE) thinks it knows what to do with that kind of file. For example: I have a series of links, I want the user to only have to left click to initiate the download. If they click on a .jpg file it will try to open it in the browser and just show the image. I want it to prompt a user for downoad regarless of file type. I am using ASP to develop this project currently. TIA,

      Wally Atkins
      Newport News, VA, USA

      D Offline
      D Offline
      DFU23
      wrote on last edited by
      #2

      Pretty simple actually ...

      'Buffer the response
      Response.Buffer = True

      'Create a Stream object
      Const adTypeBinary = 1
      Set adoStream = Server.CreateObject("ADODB.Stream")
      adoStream.Open
      adoStream.Type = adTypeBinary
      adoStream.LoadFromFile "c:\mypic.jpg" 'Need absolute path to file

      'Prepare the header information
      Response.AddHeader "Content-Disposition", "attachment; filename=mypic.jpg"
      Response.AddHeader "Content-Length", "1024" 'You can get this dynamically using FileSystemObject
      Response.Charset = "UTF-8"
      Response.ContentType = "image/jpeg" 'There are different possibilities here too

      'Send the data
      Response.BinaryWrite objStream.Read

      'Flush the response
      Response.Flush

      'Clean up
      objStream.Close
      Set objStream = Nothing

      Wally Atkins
      Newport News, VA, USA

      J 1 Reply Last reply
      0
      • D DFU23

        Pretty simple actually ...

        'Buffer the response
        Response.Buffer = True

        'Create a Stream object
        Const adTypeBinary = 1
        Set adoStream = Server.CreateObject("ADODB.Stream")
        adoStream.Open
        adoStream.Type = adTypeBinary
        adoStream.LoadFromFile "c:\mypic.jpg" 'Need absolute path to file

        'Prepare the header information
        Response.AddHeader "Content-Disposition", "attachment; filename=mypic.jpg"
        Response.AddHeader "Content-Length", "1024" 'You can get this dynamically using FileSystemObject
        Response.Charset = "UTF-8"
        Response.ContentType = "image/jpeg" 'There are different possibilities here too

        'Send the data
        Response.BinaryWrite objStream.Read

        'Flush the response
        Response.Flush

        'Clean up
        objStream.Close
        Set objStream = Nothing

        Wally Atkins
        Newport News, VA, USA

        J Offline
        J Offline
        Jonavis
        wrote on last edited by
        #3

        I found a code that goes a little further... no only does it force the download...but it allows you to list all the files in a specified (or dynamically generated) path, but it lets you select the file that you want to download, sort the files but type, name or weight. Go to the page that explains it all see ya... Jon GET TO KNOW ME

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups