How to display a web page and propose a filedownload in the same time ?

  • Thread starter Gilbert Tordeur
  • Start date
G

Gilbert Tordeur

Hello.

Context : VB 2008, Web forms.

After a clic from a user, I would like that the web server
- displays a new web page,
- and propose a file download (par Response.BinaryWrite)

I can do the first action OR the second one, but how can I do the first AND
the second action ?

(an idea : to display the web page and to execute some javascript in the
<body onload...> to send automatically a new request to the server ? How?)

Thank you for your help,
Gilbert
 
N

Nathan Sokalski

In the Load event of the new Page, include code similar to the following:


Response.ClearContent()
Response.AddHeader("content-disposition",
"attachment;filename=AnyFileName.txt")
Response.WriteFile(Server.MapPath("/Directory/YourFileName.txt"))
Response.End()


Hopefully this helps. Good Luck!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top