Hi,
I need to open PDF document in new window when i click on linkbutton
in datagrid.For that i have written code as below:
But the problem with this code is that it opens the new window ,but not
loading the pdf.Please let me know how can i solve this issue.
private void grdTest_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if(e.CommandName=="View")
{
LinkButton btn = e.Item.FindControl("linkView") as LinkButton;
GetPDF();
btn.Attributes.Add("Onclick","window.open('TestData.aspx');" +
"return false;");
}
}
Here is the GetPDF function:
public void GetPDF()
{
FileStream fs;
string fname;
fname = MapPath("../") + "via project/documents/Mass_title.pdf";
fs = File.Open(fname, FileMode.Open);
byte[] data = new byte[fs.Length];
int i=(int)fs.Length;
fs.Read(data, 0, i);
fs.Close();
Response.Clear();
Response.Charset = "";
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition",
"inline;filename=pdfTest.pdf");
Response.BinaryWrite(data);
Response.End();
}
Thanks,
VishnuHi,
You need to place the function GetPDF() in your TestData.aspx.vb 's
PageLoad.
vt
settyv@.gmail.com wrote:
> Hi,
> I need to open PDF document in new window when i click on linkbutton
> in datagrid.For that i have written code as below:
> But the problem with this code is that it opens the new window ,but not
> loading the pdf.Please let me know how can i solve this issue.
> private void grdTest_ItemCommand(object source,
> System.Web.UI.WebControls.DataGridCommandEventArgs e)
> {
> if(e.CommandName=="View")
> {
> LinkButton btn = e.Item.FindControl("linkView") as LinkButton;
> GetPDF();
> btn.Attributes.Add("Onclick","window.open('TestData.aspx');" +
> "return false;");
> }
> }
>
> Here is the GetPDF function:
> public void GetPDF()
> {
> FileStream fs;
> string fname;
> fname = MapPath("../") + "via project/documents/Mass_title.pdf";
> fs = File.Open(fname, FileMode.Open);
> byte[] data = new byte[fs.Length];
> int i=(int)fs.Length;
> fs.Read(data, 0, i);
> fs.Close();
> Response.Clear();
> Response.Charset = "";
> Response.ContentType = "application/pdf";
> Response.AddHeader("Content-Disposition",
> "inline;filename=pdfTest.pdf");
> Response.BinaryWrite(data);
> Response.End();
> }
>
> Thanks,
> Vishnu
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment