Opening PDF in new window on click of linkbutton in datagrid

S

settyv

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
 
V

vantrinh81

Hi,

You need to place the function GetPDF() in your TestData.aspx.vb 's
PageLoad.

vt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,813
Messages
2,569,696
Members
45,483
Latest member
TedDvb6626

Latest Threads

Top