////////////////////////////HTML
<asp:GridView runat="server" ID="GV_ViewPdf" AutoGenerateColumns="false" CssClass="table table-striped table-bordered table-hover
table-responsive grd3">
<Columns>
<asp:TemplateField HeaderText="SNo.">
<ItemTemplate>
<%#Container.DataItemIndex+1 %>
</ItemTemplate>
<ItemStyle Width="5%" />
<HeaderStyle Width="5%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="File
Names">
<ItemTemplate>
<asp:LinkButton runat="server"
ID="Lbtn_ViewPdf"
OnClick="Lbtn_ViewPdf_Click"
Text='<%#Eval("FileName") %>'
CommandArgument='<%#Eval("FileURL") %>'></asp:LinkButton>
</ItemTemplate>
<ItemStyle CssClass="text-left"
/>
</asp:TemplateField>
</Columns>
<RowStyle CssClass="text-center"
/>
<HeaderStyle CssClass="tblHeadNoWrap"
/>
</asp:GridView>
////////////////////////////////////// CS
protected void
Lbtn_ViewPdf_Click(object sender, EventArgs e)
{
LinkButton l = sender as
LinkButton;
Session["AllFileSNamePath"]
= l.CommandArgument.ToString();
string url = "ViewTab";
string script = string.Format("window.open('{0}');", url);
ScriptManager.RegisterStartupScript(Page,
Page.GetType(), "newPage", script,
true);
}
////////// New cs Page
protected void Page_Load(object sender, EventArgs
e)
{
if (!IsPostBack)
{
TestPdf();
}
}
private void
TestPdf()
{
lblmsg.Text = "";
string filenamae = Convert.ToString(Session["AllFileSNamePath"]);
string path = Server.MapPath("~/Resources/"
+ filenamae);
if (System.IO.File.Exists(path))
{
WebClient client = new
WebClient();
Byte[] buffer = client.DownloadData(path);
if (buffer != null)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-length",
buffer.Length.ToString());
Response.BinaryWrite(buffer);
}
}
else
{
lblmsg.Text = "Selected file not
found";
}
}
No comments:
Post a Comment