469,613 Members | 1,161 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,613 developers. It's quick & easy.

Downloading file from database causes page to stop responding???

I have binary files stored in a SQL Server table that I want the user
to be able to download from an aspx webpage. The files are displayed
on the form as "LinkButtons". When the link is clicked the code in my
event handler writes out the contents of the file which prompts the
user for the download or open dialog box. The first time you click an
attachment it opens fine but any action on the page after that doesn't
seem to work, the page just stops responding. Trying to click other
attachments do not open and clicking Buttons stop responding. Below is
my EvenHandler... any idea what I'm doing wrong? Should I not be doing
this in an event handler?


1 void LinkButton_Download_Command(object sender, CommandEventArgs
e)
2
3 {
4
5 DBFile f =
DBFile_DAL.GetByID(Convert.ToInt32(e.CommandArgume nt));
6
7
8 Page.Response.AppendHeader("Content-Disposition",
"Attachment; Filename=" + f.FileName);
9
10 Page.Response.ContentType = "application/download";
11
12 Page.Response.BinaryWrite(f.FileData);
13
14 }
15
16
Jan 4 '08 #1
6 1885
"~john" <So********@gmail.comwrote in message
news:26**********************************@l32g2000 hse.googlegroups.com...

10 Page.Response.ContentType = "application/download";
11 Page.Response.Flush();
12 Page.Response.BinaryWrite(f.FileData);
13 Page.Response.End();
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jan 4 '08 #2
10 * *Page.Response.ContentType = "application/download";
11 * *Page.Response.Flush();
12 * *Page.Response.BinaryWrite(f.FileData);
13 * *Page.Response.End();

I just tried that and got this output in IE.


The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and
then click the Refresh button, or try again later.

--------------------------------------------------------------------------------

An invalid character was found in text content. Error processing
resource 'http://greenstapler/iso/ems/Pages/CarParForm.asp...

GIF89a

Jan 4 '08 #3
Also I'm doing this in an event handler of the same web page. Do I
need to redirect to another web page to handle the download?

John

Jan 4 '08 #4
From what you describe, it would be a lot cleaner and less error-prone to
have the download appear in a separate window that can then be closed,
allowing the user to continue operating in the original page.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
"~john" wrote:
Also I'm doing this in an event handler of the same web page. Do I
need to redirect to another web page to handle the download?

John

Jan 4 '08 #5
"~john" <So********@gmail.comwrote in message
news:ca**********************************@p69g2000 hsa.googlegroups.com...
Also I'm doing this in an event handler of the same web page. Do I
need to redirect to another web page to handle the download?
That would certainly be my preferred way of doing it, yes...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jan 4 '08 #6
Thanks everyone... Also, I should mention this code is inside a
SharePoint 2007 WebPart. When copying the same code over to a regular
ASP.net webpage it appears to work fine. I'm not sure why SharePoint
would treat it differently.

John

Jan 4 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by John Lauwers | last post: by
6 posts views Thread by Henke | last post: by
23 posts views Thread by Doug van Vianen | last post: by
4 posts views Thread by PiotrKolodziej | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.