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. download file and response.redirect

download file and response.redirect

Scheduled Pinned Locked Moved Web Development
helpquestion
5 Posts 3 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.
  • E Offline
    E Offline
    ESTAN
    wrote on last edited by
    #1

    Hello, I would like to send the user the file that he would like to download and redirect the to the thank you page. I have the following in page default.aspx a href="/download.aspx?file=test.zip" here /a the download page does some code processing in the load and I do the following: string filename = Request.QueryString["file"]; HttpContext.Current.Response.Redirect(filename); and than i would like to redirect the user to thankyou.aspx, but i can't seem it to work. Can anyone help me? Thanks

    C 1 Reply Last reply
    0
    • E ESTAN

      Hello, I would like to send the user the file that he would like to download and redirect the to the thank you page. I have the following in page default.aspx a href="/download.aspx?file=test.zip" here /a the download page does some code processing in the load and I do the following: string filename = Request.QueryString["file"]; HttpContext.Current.Response.Redirect(filename); and than i would like to redirect the user to thankyou.aspx, but i can't seem it to work. Can anyone help me? Thanks

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Do a response.binarywrite to send the file, then you can redirect and the file will pop up as a download ( if you set the mime type correctly )

      Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      E 1 Reply Last reply
      0
      • C Christian Graus

        Do a response.binarywrite to send the file, then you can redirect and the file will pop up as a download ( if you set the mime type correctly )

        Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        E Offline
        E Offline
        ESTAN
        wrote on last edited by
        #3

        I can't get it to work, i have the following in the download.aspx load section string filename = Request.QueryString["file"]; string output = classDBAccess.GetDownload(filename); if (output == "false") { HttpContext.Current.Response.Redirect("Problem.aspx"); } else { string path = Server.MapPath(output); FileInfo file = new FileInfo(path); FileStream MyFileStream = new FileStream(path, FileMode.Open); long FileSize; FileSize = MyFileStream.Length; byte[] buffer = new byte[(int)FileSize]; MyFileStream.Read(buffer, 0, (int)MyFileStream.Length); MyFileStream.Close(); Response.AddHeader("Content-Length", file.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.AddHeader("content-disposition", "attachment; filename=" + file.Name); Response.BinaryWrite(buffer); Response.Redirect("Thankyou.aspx"); } Now it only goes to the thankyou page and doesn't download the file. Any clue what i do wrong? Thanks

        C G 2 Replies Last reply
        0
        • E ESTAN

          I can't get it to work, i have the following in the download.aspx load section string filename = Request.QueryString["file"]; string output = classDBAccess.GetDownload(filename); if (output == "false") { HttpContext.Current.Response.Redirect("Problem.aspx"); } else { string path = Server.MapPath(output); FileInfo file = new FileInfo(path); FileStream MyFileStream = new FileStream(path, FileMode.Open); long FileSize; FileSize = MyFileStream.Length; byte[] buffer = new byte[(int)FileSize]; MyFileStream.Read(buffer, 0, (int)MyFileStream.Length); MyFileStream.Close(); Response.AddHeader("Content-Length", file.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.AddHeader("content-disposition", "attachment; filename=" + file.Name); Response.BinaryWrite(buffer); Response.Redirect("Thankyou.aspx"); } Now it only goes to the thankyou page and doesn't download the file. Any clue what i do wrong? Thanks

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Oh, the redirect might kill the write.

          Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          1 Reply Last reply
          0
          • E ESTAN

            I can't get it to work, i have the following in the download.aspx load section string filename = Request.QueryString["file"]; string output = classDBAccess.GetDownload(filename); if (output == "false") { HttpContext.Current.Response.Redirect("Problem.aspx"); } else { string path = Server.MapPath(output); FileInfo file = new FileInfo(path); FileStream MyFileStream = new FileStream(path, FileMode.Open); long FileSize; FileSize = MyFileStream.Length; byte[] buffer = new byte[(int)FileSize]; MyFileStream.Read(buffer, 0, (int)MyFileStream.Length); MyFileStream.Close(); Response.AddHeader("Content-Length", file.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.AddHeader("content-disposition", "attachment; filename=" + file.Name); Response.BinaryWrite(buffer); Response.Redirect("Thankyou.aspx"); } Now it only goes to the thankyou page and doesn't download the file. Any clue what i do wrong? Thanks

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            Each request only has one response. You can't both send the file and send a redirection page. Open a new window to get the file, and open the thankyou page in the current window. You can do this with Javascript.

            --- single minded; short sighted; long gone;

            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