Click here to Skip to main content
15,902,002 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to show pdf or image file retreived from FTP server in IFrame control

What I have tried:

C#
string ParentFolder = ConfigurationManager.AppSettings["DocReqFolder"].ToString();
              int l = filePath.IndexOf('.') + 1;
              string Extn = filePath.Substring(l);
              Ftp_FileHandler Ftp = new Ftp_FileHandler();
              Ftp.FtpPath_withCredents();
              Ftp.FTP_DownloadFile(filePath, ParentFolder);
              var context = System.Web.HttpContext.Current;
              context.Response.Clear();
              context.Response.AddHeader("Content-Disposition", "attachment; filename=" + filePath);
              if (Extn.Contains("PDF") == true || Extn.Contains("pdf") == true)
                  HttpContext.Current.Response.ContentType = "application/pdf";
              else
                  HttpContext.Current.Response.ContentType = "application/octet-stream";
              context.Response.OutputStream.Write(Ftp.file, 0, Ftp.file.Length);
              context.Response.End();
Posted
Updated 26-Jun-18 3:52am
v2
Comments
Kornfeld Eliyahu Peter 26-Jun-18 7:45am    
So, what's wrong with your code?
khaleelsyed 26-Jun-18 8:32am    
abov code will download the file to my system.but i want show in iframe control
Kornfeld Eliyahu Peter 26-Jun-18 8:38am    
Displaying file inside the browser or not is not a decision you always can make. It depends ion end user's preferences and file type too...
khaleelsyed 26-Jun-18 8:44am    
end user preference is to show the retrieved file in iframe.
F-ES Sitecore 26-Jun-18 7:46am    
make the src of the iframe the url of the page that code is on.

Set iframe's src attribute to point to the document:
HTML
<iframe src="https://i.ytimg.com/vi/7rB0Hvt1i3Q/maxresdefault.jpg">
  <p>Your browser does not support iframes.</p>
</iframe>

If you want to stream the content instead to pint to the file directly you can see here how:
Stream Your Documents Using Simple Web Page[^]
 
Share this answer
 
Comments
khaleelsyed 26-Jun-18 9:12am    
Can you please provide the code with example. i am not sure how set src to byte array.
Kornfeld Eliyahu Peter 26-Jun-18 9:15am    
You can not! For that to understand you have to read and learn!
Setting the Content-Disposition to attachment forces the browser to download the file.

Change it to inline to let the browser display the file inline:
C#
context.Response.AddHeader("Content-Disposition", "inline; filename=" + filePath);

Content-Disposition - HTTP | MDN[^]

NB: Some browsers don't support displaying PDFs inline. You'll need to use a library like PDF.js[^] if you need to support them.
 
Share this answer
 
Comments
khaleelsyed 28-Jun-18 9:24am    
Thanks for your solution. PDF files is showing in iframe but images not.
how to fix this issue.

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