Opening pdfstream in new window in asp.net-Help me

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;

Label lbl=e.Item.FindControl("lblText") as Label ;
sp.DmsID=lbl.Text;
GetPDFDoc(sp);


btn.Attributes.Add("Onclick","window.open('TestData.aspx');" +
"return false;");
}
}


Here is the GetPDF function:


public void GetPDFDoc(SearchParams sp)
{
//Tentative tr=new Tentative();
Minute min=new Minute();

MemoryStream pdfStream = new MemoryStream();

pdfStream = min.GetMinuteOrderPdf(sp);

Response.Clear();
Response.Charset = "";
Response.ContentType = "application/pdf";
Response.AddHeader( "content-length", System.Convert.ToString(
pdfStream.Length ) );
Response.BinaryWrite( pdfStream.ToArray() );

Response.End();
}

Thanks,
Vishnu
 
N

Nicholas Paldino [.NET/C# MVP]

Well, you are having it open TestData.aspx, but the CURRENT page is the
one that is processing the data.

What I would do is add a query parameter to TestData.aspx which you can
use to load the document in THAT request when the new window opens.

Also, you might want to revise your GetMinuteOrderPdf routine to take a
stream to write to, since you are basically performing the write for your
PDF document twice.

Hope this helps.
 

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

Top