Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi guys im having problem on my codes, after i upload the and download it. It downloads the file but after that i click the other button is still download the file. Can you help me please. and here's my codes

What I have tried:

This is my code to view the file.
if (lblFile.Text != "")
{
trAttachedFile.Visible = true;
lbtnDownload.PostBackUrl = "~/Download.aspx?file=" + lblFile.Text;
}
else
{
trAttachedFile.Visible = false;
}


And here's my code to download the file(Download.aspx)

private bool StartDownload()
{
if (DownloadID != "")
{
string downloadPath = WebConfigurationManager.AppSettings["SubPic"].ToString() + DownloadID;
FileInfo downloadFile = new FileInfo(downloadPath);

if (downloadFile.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + downloadFile.Name);
Response.AddHeader("Content-Length", downloadFile.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(downloadFile.FullName);
Response.End();
return true;
}
}
return false;
}
Posted
Updated 1-Oct-17 10:06am
v2

1 solution

Yeah, and? That's what is supposed to happen. The browser downloading a file is separate operation from everything else going on on the page.
 
Share this answer
 
Comments
Member 13427032 4-Oct-17 10:17am    
Is there a way to prevent downloading the file when clicking the other button? or do i to include the download code on the same page?
Dave Kreskowiak 4-Oct-17 10:31am    
Nope. A file download is a "fire and forget" operation.
Member 13427032 5-Oct-17 14:47pm    
And still after i click the download(linkbutton) and i click another button it still download the file. Can you help me please to fix my codes.
Dave Kreskowiak 14-Oct-17 22:07pm    
Again, since a file download is a "fire and forget" operation, you have no way of knowing when the file download is complete and no way to prevent the second file from being downloaded.

In today's web, it also doesn't even make sense to do that!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900