简体   繁体   中英

Download file from database asp.net

I am reading PDF data from a database field (database field format is 'Data') and I have converted it into bytes using data reader GetBytes and I have it right because it's working fine in other operation.

I added a button on aspx page, and, on button click, I have the below code to download it:

Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename="test.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(byteArray);
Response.End();

But it's not doing any thing. I mean when I click the button I can step through it but after response.end() nothing happens.

Any idea what I am doing wrong?

Move your button outside of update panel. You also need to add postback trigger as Oguz Ozgul mentioned it. Additionally you should add ThreadAbortException catch also just to stay safe...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM