File Download dialog events in ASP.NET

Posted on 2010-01-03
Medium Priority
Last Modified: 2012-05-08
Hi Everyone,

I have been breaking my head over a problem from the past couple of days.
My problem is that I have to provide an option for the user to upload and download files to the server. I have already done this by providing the file upload control for uploading the file and later providing a link for all uploaded files in a gridview, clicking on which will download the file to client's local machine at the path of his choice. When the user clicks on the link he is prompted with a file download dialog after which he can choose to open or save the file or cancel the download.
What I am required to do is to set a flag in my database whenever a user downloads a file. To do this I need to find out which of the 3 buttons (Open, Save, Cancel) the user has clicked. Only if the user Opens/Saves the file, should I update the flag in the database. So is there any way either through javascript or ASP.NET that I can track such an event and update the flag.
Question by:Shashidhar_Shenoy
  • 3
LVL 15

Accepted Solution

rajeeshmca earned 500 total points
ID: 26165899

 i dont think that can be done... That is client side browser event. Instead u can make an update in to the database while he clicks the Link for the download

Author Comment

ID: 26166470
Thanks for the quick reply.

In fact that is exactly what I am doing now. But the user could cancel the download after clicking on the download link. That is why I am trying to look for the events (if any) of file download dialog.

Is there any alternate way in which I could achieve the same result?
LVL 28

Assisted Solution

sybe earned 500 total points
ID: 26169725
Agree with rajeeshmca. You can not do that. At the moment the user clicks the link, the file is transferred to the client (to the browser cache). The dialogue only asks the user what to do with the file which is already (partly) in their own cache.

You should also realize that an HTTP-request is not necessarily done by a browser, or that every browser must have the same buttons.

Author Comment

ID: 26300969
Thanks guys for the reply. After a lot of googling around even I have come to a conclusion that it is not possible to do that. Instead I have chose to warn the user by using a javascript confirm dialog saying that if he proceeds then the flag will be set in the database. If he clicks OK on the confirm dialog then after that even if he chooses to cancel the download later the flag will be set in the database.

Author Closing Comment

ID: 31672112
Although I did not get a solution to my actual problem I atleast came to know that what I was trying to achieve was not possible and that I had to look for another alternative. Thanks to both the experts for their quick replies.

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses
Course of the Month17 days, 10 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question