javascriptasp.netasp.net-webpages

Detecting Download file dialog?


Is there any way I can detect opening of the download file dialog box on web pages like hyperlink click event occurs and download file dialog box appears?

And can I edit the filename in it? Like attaching some website name along with filename, so when the user downloads any file, it automatically renames it to website-filename.pdf, etc., programmatically

Can we use input tag for it? Or do I have to make a custom control for it?


Solution

  • You can just make a hyperlink with its href to a regular file, your browser will prompt to download it.

    As for renaming the file, all you could do is create a special page which sends the file contents and correct headers, and specifying another name. You'll have to send the content-disposition header, as such:

    Content-disposition: attachment; filename=yourfilename.extension