473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Redirect after file download - VB.NET - ASP.NET

I have a form which allows the user to download a simple text file. They click on the download button and it brings up the "Save As" dialog. Once they save the file, I want them to be redirected to another page.

Here is the code I'm using:

Expand|Select|Wrap|Line Numbers
  1.             Response.ContentType = "text/plain"
  2.             Response.AppendHeader("Content-Disposition", "attachment; filename=Security.PCC")
  3.             Response.TransmitFile(PassGen.Path & "Security.pcc")
  4.             Response.End()
  5.             Response.Redirect("password.aspx?pw=" & password)
  6.  
  7.  
I've tried switching around the .End and .Redirect statements. Either it redirects, but the file doesn't download, or it downloads but doesn't redirect. What am I missing?
Mar 12 '08 #1
9 21241
jeffstl
432 Expert 256MB
Take out the response.end

That stops all execution on the spot.

Plus with the redirect you dont need it at all..
Mar 12 '08 #2
Thanks. But when I try that, the "save' dialog never shows. It justs goes directory to the redirect url. I tried adding the extra parameter to the redirect as well

Expand|Select|Wrap|Line Numbers
  1.                 Response.ContentType = "text/plain"
  2.                 Response.AppendHeader("Content-Disposition", "attachment; filename=Security.PCC")
  3.                 Response.TransmitFile(PassGen.Path & "Security.pcc")
  4.                 Response.Redirect("password.aspx?pw=" & password, True)
  5.  
Mar 12 '08 #3
jeffstl
432 Expert 256MB
Thanks. But when I try that, the "save' dialog never shows. It justs goes directory to the redirect url. I tried adding the extra parameter to the redirect as well

Expand|Select|Wrap|Line Numbers
  1.                 Response.ContentType = "text/plain"
  2.                 Response.AppendHeader("Content-Disposition", "attachment; filename=Security.PCC")
  3.                 Response.TransmitFile(PassGen.Path & "Security.pcc")
  4.                 Response.Redirect("password.aspx?pw=" & password, True)
  5.  

Hmm. I have never actually done a transmitFile before so I guess Im not sure.

It sounds like you need a buffer or something?

Or you need to somehow be able to somehow have a timer for the redirect....I will tell you I did a quick scan on google after I saw your response and it doesn't look like you are alone in this problem ;-)
Mar 12 '08 #4
jhardman
3,406 Expert 2GB
I think you are seeing a basic internet deficiency. I would suggest opening the file in a new window, and have the same function which opens the file redirect the page. It would be easier to do in javascript, I think.

Jared
Mar 17 '08 #5
Thanks Jared. I had tried that. It worked, but not as efficiently as I wanted to. I almost have it working now. The whole reason I wanted to redirect was to display a password for the user. I'm trying now just to post the password to the same page as the download.

It seems like it should be working, but its not. Basically, I have this control ('PassGen') that creates a text file and also a password for that file. I want to display the password to the user and have them be able to download the file.

Expand|Select|Wrap|Line Numbers
  1. Private Sub generate_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2.  
  3.         If Not String.IsNullOrEmpty(Session("password")) Then
  4.             lblPassword.Text = "Your password is            " & Session("password") 'display password
  5.             Session("password") = String.Empty 'reset the password
  6.         Else
  7.             PassGen.Path = System.AppDomain.CurrentDomain.BaseDirectory() 'set path to create file
  8.             password = PassGen.CreatePasswordFile 'create text file and password
  9.             Session("password") = password 'set session password
  10.         End If
  11.  
  12.     End Sub
  13.  
  14.     Protected Sub btnDownload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDownload.Click
  15.  
  16.         If System.IO.File.Exists(filename) Then
  17.             Response.ContentType = "text/plain"
  18.             Response.AppendHeader("Content-Disposition", "attachment; filename=Security.PCC")
  19.             Response.TransmitFile(PassGen.Path & "Security.pcc")
  20.             Response.End()
  21.         End If
  22.  
  23.     End Sub
  24.  
  25.  
Basically if the password is blank, then the file hasn't been generated, so I go ahead and generate it. And when they click on the download button, the generate_load is called again, which should then display the message. When I step through it, it hits that line of code but never displays the password, which I don't understand. Is there a better way to do this?
Mar 18 '08 #6
jhardman
3,406 Expert 2GB
Matt,

Looking at your code, it is apparent that this is not ASP classic. Give me some details (what version and language you are using, what IDE) and I will try to recommend an expert to help.

Jared
Mar 18 '08 #7
I'm using VS 2005. I'm more of a VB.NET guy, so I'm working mostly with the VB behind the ASP
Mar 19 '08 #8
jhardman
3,406 Expert 2GB
I'm using VS 2005. I'm more of a VB.NET guy, so I'm working mostly with the VB behind the ASP
OK, I'm moving this post to the .NET forum, the ASP forum focuses on "classic" ASP and even though experts crossover, we try to keep the threads separate. If someone here doesn't pick up on it, try sending a PM to me or to Frinavale (the leader of the .NET forum) - I think this would be close to her specialty.

Jared
Mar 19 '08 #9
Jared,

Thank you very much for doing that. But I think I figured out a way to get it to work the way I wanted. And I also found that the reason the label caption wasn't being updated had something to do with the download function. When I commented out the download code, the label updated fine. Here is what I'm doing now:

Expand|Select|Wrap|Line Numbers
  1.  If Not Page.IsPostBack Then
  2.             If System.IO.File.Exists(filename) Then
  3.                 System.IO.File.Delete(filename)
  4.             End If
  5.             PassGen.Path = System.AppDomain.CurrentDomain.BaseDirectory() 'set path to create file
  6.             password = PassGen.CreatePasswordFile 'create text file and password
  7.             lblPassword.Text = "Your password is " & vbTab & password '& ".  It came from the path: " & filename
  8.         End If
  9.  
  10.     End Sub
  11.  
  12.     Protected Sub btnDownload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDownload.Click
  13.  
  14.         If System.IO.File.Exists(filename) Then
  15.             Response.ContentType = "text/plain"
  16.             Response.AddHeader("Refresh", 0.1)
  17.             Response.AppendHeader("Content-Disposition", "attachment; filename=Security.PCC")
  18.             Response.TransmitFile(PassGen.Path & "Security.pcc")
  19.             Response.End()
  20.         End If
  21.  
  22.     End Sub
  23.  
  24.  
Basically I just display the password first on form load and then have them download. Ideally I wanted to show the password after they hit the download button, but its not that big of a deal. Thanks again for your help :)
Mar 20 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Brandon Walters | last post by:
I wrote a file download module for my website. The reason for the file download module is that my website downloads work on a credit based system. So I need to keep track of and limit daily...
22
by: MyndPhlyp | last post by:
I am pushing a file download to the client. The ASP used to generate and push the file is triggered by an <a target="_blank" href="something">. The VBScript uses Response.Clear...
0
by: Buddy Ackerman | last post by:
I am trying to implment a file download via a link such that when clicked, instead of starting the default application for that type of file the user will be presented with a download dialog...
0
by: Rhys666 | last post by:
Basically I have a link that opens my download page and the querystring identifies the type of 'template' Excel spreadsheet has asked to download. The download page reads the querystring,...
0
by: karups | last post by:
hi, Can some one help me out? How to Force file download box when clicking on a link for a .pdf file. Normally it opens the pdf in IE itself, instead it should ask for (open , save and...
1
by: Cindy H | last post by:
Hi I used the code below to automatically open a pdf file when the user clicks on a menu option. It works great on local machine, but when I uploaded it to hosting site and then tried it, I...
7
by: mistral | last post by:
I use htaccess to protect directory and granting access to download file only for the authorized users. Just want implement simple PHP file download counter for single file. I need track the number...
4
by: L. Scott M. | last post by:
I am invoking a file download using the following code: Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=" + downloadFile.Name);...
3
by: tshad | last post by:
I have a function that downloads a file to the users computer and it works fine. The problem is that I then want the program to rename the file (file.move) to the same name plus todays date. ...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.