Abraham Olatubosun

Abraham Olatubosun

  • NA
  • 471
  • 113.7k

How to view PDF file before downloading

May 11 2017 3:53 PM

Dear code master, I believe you all doing well.

I am writing an application where I uploaded a pdf file as varbinary(Max) this work file.

I want the user to view the pdf file first before downloading, when I run the application and click the button I get the pdf viewer inline but it display’s Failed to load PDF document.

My code is shown below:

  1. var DT = new DataTable();  
  2.        DT = ConnectAll.DownloadFile(TextBox1.Text.Trim());  
  3.        foreach (DataRow r in DT.Rows)  
  4.        {  
  5.            byte[] myFile = (byte[])r["docu"];  
  6.            Response.Clear();  
  7.            Response.Buffer = true;  
  8.   
  9.            Response.ContentType = "application/pdf";  
  10.            Response.AddHeader("content-disposition""inline;filename=MME.pdf");  
  11.   
  12.            Response.Charset = "";  
  13.            Response.Cache.SetCacheability(HttpCacheability.NoCache);  
  14.            Response.BinaryWrite(myFile);  
  15.   
  16.            Response.End();  
  17.        }  

Can anybody help me ?

Thank you all

 

Answers (4)