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