Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi all,

i need to open a pdf file within web page itself without ask me to save/cancel/open.

i have coding for how to open pdf file with the save options and outside of web page . i am posting for that code for your reference.
path="" need to mention here.
       System.Net.WebClient client = new System.Net.WebClient();
       Byte[] buffer = client.DownloadData(path);

       if (buffer != null)
       {
           Response.ContentType = "application/pdf";
           Response.AddHeader("content-length", buffer.Length.ToString());
           Response.BinaryWrite(buffer);
       }

i need just open inside the web page itself without saking open or save.
Posted
Updated 4-Aug-11 0:21am
v2

Add this line after Response.ContentType.
Response.AppendHeader("content-disposition", "inline; filename=sample.pdf");

or just give the URL path of the pdf like below.
Response.Redirect("www.sample.com/folder/test.pdf"); //In your case path
 
Share this answer
 
v2
Try as below code.

C#
string path = Server.MapPath("PDFFileFolder") + @"\MyPDFFile.pdf";
System.Net.WebClient client = new System.Net.WebClient();
Byte[] buffer = client.DownloadData(path);

 if (buffer != null)
 {
   Response.ContentType = "application/pdf";
   Response.AddHeader("content-length", buffer.Length.ToString());
   Response.BinaryWrite(buffer);
 }
 
Share this answer
 
Comments
RaisKazi 4-Aug-11 6:49am    
Since you have updated your Question, your code is now similar to what I proposed. This should open your PDF in browser itself. Make sure Path of your PDF is correct.
RaisKazi 4-Aug-11 6:58am    
Have you tried my code? It does opens up PDF file in the same browser. No point in down voting Solution without trying.
Rajesh Duraisamy 4-Aug-11 7:01am    
i tried. but it open out of browser and ask me to save .
Toniyo Jackson 4-Aug-11 7:03am    
Check my updated answer
Rajesh Duraisamy 4-Aug-11 7:02am    
i have give path correctly
Hi
try this one

C#
Response.Redirect("~/Yourfolder/file.pdf"); 



Thanks.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900