-1

I am using a PDF generater that utlizes HttpResponse. Is there a way (perhaps passing a header tag) to open the PDF in a NEW windows instead of the same one? I don't want the user to be directed away from the website...

Here's the code I'm using:

System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;        response.Clear();
response.AddHeader("Content-Type", "application/pdf");
response.AddHeader("Content-Disposition",
    "inline; filename=" + downloadName + "; size=" + downloadBytes.Length.ToString());
response.Flush();
response.BinaryWrite(downloadBytes);
response.Flush();
response.End();
dcolumbus
  • 9,596
  • 26
  • 100
  • 165

3 Answers3

1

You cannot do that on server side if you have not generated the link yourself. But if you have, then as Robert said, provide a target with the <a> link.

There is a server-side alternative and that is to set the content type to application/octect-stream so that the file is download and user will be able to open it with the application of choice outside browser. See here for more.

You also need to use content disposition header to provide the file name so that client can know what file type is it after it has been downloaded as binary.

Content-Disposition: attachment; filename=my.pdf;
Aliostad
  • 80,612
  • 21
  • 160
  • 208
  • "You cannot do that on server side if you have not generated the link yourself" - That's what I wanted to know. Thanks Aliostad. – dcolumbus Jan 28 '11 at 01:22
0

You presumably have a link on your site that directs the user to the URL where this PDF generation is done. In that link, add target="_blank" to the <a> tag.

Robert Levy
  • 28,747
  • 6
  • 62
  • 94
  • ... I don't mean to be a jerk but, duh? :P I'm asking whether or not it's possible from the server-side. I obviously know how to execute a `href` or javascript call. – dcolumbus Jan 28 '11 at 01:18
0

If what you're really asking is how to make the save dialog to show instead of having the PDF loaded into your browser, then you need to modify your header. You are setting Content-Disposition to 'inline', change that to 'attachment'

http://support.microsoft.com/kb/260519

Babak Naffas
  • 12,395
  • 3
  • 34
  • 49