Hi @Gani_tpt,
You can try using Literal control to view PDF files in browser.
You can use the HTML OBJECT tag to embed PDF into the browser. Generate an HTML string of the OBJECT tag, in which the path of the PDF file is set. Then set the HTML string to the Literal tag.
Details are as follows:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<script type='text/javascript'>
function openModal() {
$('[id*=PopModal]').modal('show');
}
</script>
<div class="modal fade" id="PopModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
×</button>
<h4 class="modal-title">Customer Details</h4>
</div>
<div class="modal-body">
<div class="col-lg-12 col-sm-12 col-md-12 col-xs-12">
<div class="form-group">
</div>
<div class="form-group">
<asp:Literal ID="ltEmbed" runat="server" />
</div>
</div>
</div>
<div class="modal-footer">
<asp:Button ID="btnDownload" runat="server" Text="Download" OnClick="DownloadFile" />
<button type="button" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
protected void Display(object sender, EventArgs e)
{
int rowIndex = Convert.ToInt32(((sender as LinkButton).NamingContainer as GridViewRow).RowIndex);
GridViewRow row = gvCustomers.Rows[rowIndex];
string FPath = (row.FindControl("HiddenField1") as HiddenField).Value;
Session["FPath"] = FPath;
if (!string.IsNullOrEmpty(FPath))
{
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(FPath));
ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);
}
}
protected void DownloadFile(object sender, EventArgs e)
{
string FPath = Session["FPath"].ToString();
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(FPath));
Response.WriteFile(FPath);
Response.End();
}
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.