Hi @Peter_1985,
Hope the following two examples will help you.
<asp:FileUpload ID="fuUpload" runat="server" />
<asp:Button Text="Submit" OnClick="OnSubmit" runat="server" />
<hr />
<asp:Literal ID="ltEmbed" runat="server" />
protected void OnSubmit(object sender, EventArgs e)
{
ltEmbed.Visible = true;
if (!System.IO.Directory.Exists(Server.MapPath("~/Files")))
{
System.IO.Directory.CreateDirectory(Server.MapPath("~/Files"));
}
fuUpload.SaveAs(System.IO.Path.Combine(Server.MapPath("~/Files"), System.IO.Path.GetFileName(fuUpload.PostedFile.FileName)));
string file = "~/Files/" + System.IO.Path.GetFileName(fuUpload.PostedFile.FileName);
string embed = "<object data=\"{0}\" type=\"application/pdf\" width=\"500px\" height=\"300px\">";
embed += "If you are unable to view file, you can download from <a href = \"{0}\">here</a>";
embed += " or download <a target = \"_blank\" href = \"http://get.adobe.com/reader/\">Adobe PDF Reader</a> to view the file.";
embed += "</object>";
ltEmbed.Text = string.Format(embed, ResolveUrl(file));
}
<div>
<asp:Button ID="bttnpdf" runat="server" Text="Click for open PDF" Font-Bold="True" OnClick="bttnpdf_Click" />
</div>
protected void bttnpdf_Click(object sender, EventArgs e)
{
string FilePath = Server.MapPath("javascript1-sample.pdf");
WebClient User = new WebClient();
Byte[] FileBuffer = User.DownloadData(FilePath);
if (FileBuffer != null)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", FileBuffer.Length.ToString());
Response.BinaryWrite(FileBuffer);
}
}
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.