Recently I had to write a few lines of code to download a PowerPoint presentation file from one of my
ASP.NET websites. I would like to share the block of code I used for this purpose.
Response.ContentType = "application/x-mspowerpoint";
Response.AddHeader("Content-Disposition", "attachment; filename=" + file);
Response.ContentType should be set correctly. I have used
You need to set the correct ContentType. For example, for MS Word you should set
a GIF image you should set
for PDF you should set
Here is the reference to set
Another important information:
To have it work correctly in IE you need to write the code in the
Page_load event. So, for this you may create a page
Download.aspx and redirect to that page when
you click the Download button with file information in the querystring.
Hope it helps.