This is a simple example to show how to download pdf/doc file. Here I
am using two link button one is for doc and another is for pdf file download.
<%@
Page
Language="C#"
AutoEventWireup="true"
CodeFile="Default.aspx.cs"
Inherits="_Default"
%>
<!DOCTYPE
html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml">
<head
runat="server">
<title></title>
</head>
<body>
<form
id="form1"
runat="server">
<div>
<asp:linkbutton
id="LinkButtonDownloadDoc"
runat="server"
text="Download WORD"
style="color:
Maroon;
font-weight:
bold;"
onclick="LinkButtonDownload_Click"
/>
</div>
<div>
</div>
<div>
<asp:linkbutton
id="LinkButtonDownloadPdf"
runat="server"
text="Download PDF"
style="color:
Navy;
font-weight:
bold;"
onclick="LinkButtonDownloadPdf_Click"
/>
</div>
</form>
</body>
</html>
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
public
partial class
_Default : System.Web.UI.Page
{
protected
void Page_Load(object
sender, EventArgs e)
{
}
protected
void LinkButtonDownload_Click(object
sender, EventArgs e)
{
Response.ContentType =
"Application/msword";
Response.AppendHeader("Content-Disposition",
"attachment; filename=Test.docx");
Response.TransmitFile(Server.MapPath("~/Files/Test.docx"));
Response.End();
}
protected
void LinkButtonDownloadPdf_Click(object
sender, EventArgs e)
{
Response.ContentType =
"Application/pdf";
Response.AppendHeader("Content-Disposition",
"attachment; filename=Test_PDF.pdf");
Response.TransmitFile(Server.MapPath("~/Files/Test_PDF.pdf"));
Response.End();
}
}
Output: When you click on
second button the FileDownload dialogbox will open like as follows:

Figure: FileDownload
dialogbox Displpay File name and File type and size.
Now click on Save button you will get downloaded pdf file at desire location on
your system.