I have this code..
<li><a href="downloads/PDF_File.pdf">PDF</a></li>
but it opens the pdf file, now I am new to ASP.NET, how do I get the download dialog box to open?
I have this code..
<li><a href="downloads/PDF_File.pdf">PDF</a></li>
but it opens the pdf file, now I am new to ASP.NET, how do I get the download dialog box to open?
Basically, what is happening here is the normal behaviour for pdf files. IIS by default serves up the "pdf" MIME-type for any pdf files in your web application. When you access a pdf in your application, the browser reads the MIME-type and understands that you are accessing a pdf file.. most browsers will want to display it in their built-in PDF reader instead of prompting you to save it. If you really need a download dialog box to show up for pdfs, you could change the MIME-type for pdf in web.config so that IIS will serve up pdfs as a basic filetype within your application:
<configuration>
<system.webServer>
<staticContent>
<remove fileExtension=".pdf" />
<mimeMap fileExtension=".pdf" mimeType="application/octet-stream" />
</staticContent>
</system.webServer>
</configuration>
Note: You should first remove the MIME-type you are manually setting in web.config, because a MIME-type for the same extension may already be set at the application level.
Now IIS will serve up pdf files as a basic/unknown filetype and they will be downloadable. This works for any filetype if you just swap out '.pdf' for a different extension.
I don't know how to do this with existing files, but a while ago I wrote a piece of code combining iTextSharp and an ASP.net (framework 4) MemoryStream object to create then download pdf files, I hope this could be helpful :
MemoryStream msPDF = new MemoryStream();
// do some stuff with iTextSharp ...
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=myPdf.pdf"); // open/save dialog
Response.BinaryWrite(msPDF.ToArray());