Downloading file

M

M. Noroozi Eghbali

Hi,

I need to download a file using OnClick event or Command of a ASP button. Is
there any possible code for this?

In ASPX file:
<ASP:Button id="button1" runat="server" text="Start Download"></ASP:Button>

In CS file:
private void button1_Click(object sender, System.EventArgs e)
{
//some actions before downloading
//download file
}


Thank you,
Mehrdad
 
K

Kyle M. Burns

In the event handler, register some client side javascript to execute a
Window.Open(), specifying the file that you wish to download.
 
M

M. Noroozi Eghbali

Thank you for your response. al of the answers are really helpful.

Bests,
Mehrdad
 
M

Michael Nemtsev

Hello M. Noroozi Eghbali,

Smth like below

Response.ContentType = "application\octet-stream";
string filename = "c:\\downloads\\hi.doc";
System.IO.FileStream downloadFile = new System.IO.FileStream(filename,
IO.FileMode.Open);
Response.Write(downloadFile.Length() & "#");
downloadFile.Close();
Response.WriteFile(filename);
Response.Flush();

M> I need to download a file using OnClick event or Command of a ASP
M> button. Is there any possible code for this?
M>
M> In ASPX file:
M> <ASP:Button id="button1" runat="server" text="Start
M> Download"></ASP:Button>
M> In CS file:
M> private void button1_Click(object sender, System.EventArgs e)
M> {
M> //some actions before downloading
M> //download file
M> }
M> Thank you,
M> Mehrdad
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsch
 
A

Adam Clauss

If the file is available through the website, you can just use
Response.Redirect()
 

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