Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I want to display a PDF residing on disc of server from Iframe.

I am using below code:

<iframe id="if1" src='file:E:\Shared-Files\DisplayPDF.pdf' width="700px" height="150px"></iframe>

But I am not able to view this PDF.
Can anyone suggest what is correct way to display PDF inside Iframe?

(later on in .cs page I will set src attribute as per file name so as to make it dynamic:
if1.Attributes.Add("src", pdfPath);)

I tried using <object> but I do not want to use it.

Thanks in advance,
Janie D
Posted

1 solution

Wrong question. Paths in a Web application are irrelevant to the application path. Relative URI addressing is based on the location of a current page. In other words, if your host page has some location, and you use the URI of the iframe content something as "frames/myFrame.html" (same as "./frames/myFrame.html"), it means the resource is taken from the sub-directory "frames" of the directory of your host page location.

But URIs like "file:E:\Shared-Files\..." you are trying to use are simply illegal in Web application. The HTTP server executes your application is a sandboxed environment, which allows you to access only the file system object under the site's root directory. So, the absolute directory can be only calculated based on this root directory. In ASP.NET, it can be done based on MapPath: http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx[^].

As to URLs, the should either be built based on the site's root using the "http://" or "https://" URI schema, or, more often, should be relative.

—SA
 
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