Search code examples
asp.netdownloadtransmitfile

ASP.Net Transmit File


I am writing a webapplication in ASP.net.

I am trying to make a file dialog box appear for downloading something off the server.

I have the appropriate file data stored in a variable called file.

File has fields: FileType - The MIMEType of the file
FilePath - The server-side file path

Here's the code so far:

Response.Clear();
Response.ContentType = file.FileType;
Response.AppendHeader("Content-Disposition", "attachment; filename=" +     GetFileName(file));
Response.TransmitFile(file.FilePath) ;
Response.End(); 

GetFileName is a function that gets me the filename from an attachment object. I only store the path.

The above code is in a function called "Download_Clicked" that is an event that triggers on click. The event is mapped to a LinkButton.

The problem is that when I run the above code, nothing happens. The standard dialog box does not appear.

I have attempted the standard trouble-shooting such as making sure the file exists, and ensuring the path is correct. They are both dead on the mark.

My guess is that because my machine is also the server, it may not be processing properly somehow.

Thanks in advance.

Edit 1: Attempted putting control onto another page, works fine.

Edit 2: Resolved issue by removing control from AJAX Update Panel.


Solution

  • See edit on initial post.

    Removed Ajax Update Panel to resolve the error. The panel was stopping the post back to the server.

    For more info, see Cris Valenzuela's comment.