1

I have a pdf file and i have shown it in web broswer like this,

  WebClient client = new WebClient();
  Byte[] buffer = client.DownloadData(sFileName);
  if (buffer != null)
   {
    Response.Clear();
    Response.ContentType = "application/pdf";
    Response.Flush();
    Response.BinaryWrite(buffer);
   }

But my problem is when i am going to show the pdf in local server it is showing all the pages,but same code when run in live server it is showing some of pages blank.I have tested so many days for this and not found any result.

Please help for this problem. Thanks

mns
  • 663
  • 2
  • 8
  • 22
  • Have you tried to put Response.Flush() after Response.BinaryWrite(buffer) ? – Qorbani Jan 05 '12 at 05:56
  • Also you may need to add Response.AddHeader("Content-Disposition", "attachment; filename=result.pdf") after ContentType – Qorbani Jan 05 '12 at 05:58
  • have a look at this link and the answers : http://stackoverflow.com/q/848679/168371 – Pankaj Kumar Jan 05 '12 at 06:14
  • Try Response.Buffer =true; Response.AddHeader("Content-Disposition", "attachment; filename=fiename.pdf") and add Response.End() after Response.BinaryWrite(); If you do not want to download file. Response.TransmitFile(@"......\aaa.pdf") – JayOnDotNet Jan 05 '12 at 08:59
  • @Qorbani , can u please say why it is required to Response.Flush() at the end .I think that Response.Flush() will release any resource and Response.End() will cause terminate the buffering process to the Response.But my problem is first 5 pages is blank and others are as usual. I am confused. Thanks for ur Help – mns Jan 06 '12 at 06:43
  • @mns , The Flush method sends buffered output immediately so client can start consuming it, so doing flush after Response.Clear doesn't make sense because there is nothing in buffer to flush! That's why I recommend doing flush after BinaryWrite :-) If you still have an issue I recommend changing your method of downloading and sending to Response. – Qorbani Jan 06 '12 at 16:06

0 Answers0