Click here to Skip to main content
15,885,899 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i tried displaying pdf tat is inside application ath and it works. But i need to display pdf outside from other drives how do i do it?
this is my code:
string path1 = Session["path1"].ToString();
string filepath = Server.MapPath(path1);
System.Web.UI.AttributeCollection aCol = iFrame1.Attributes;
aCol.Add("src", filepath);
where i get path from a database and i also tried server.mappath and gor error of using physical path
help me..
Posted

Everything depends on where that outside from other drives lies relative to the client browser. What exactly does appear in the html code. The fact that you can reach the pdf on the server does not implies that the client can reach it too - and this involves access rights, protocols, exposed services and even intranet/extranet kind of questions. So if you want to be sure that your client can read the resource you need to ensure that your web application is serving it, even if it is stored outside it's scope.

Your server side should transmit the file - don't rely on the client to reach it. Look here: http://weblogs.asp.net/dmiyamasu/archive/2008/02/25/save-server-memory-with-response-transmitfile.aspx[^]

A more advanced view of this: http://davidarodriguez.com/blog/2013/05/29/downloading-files-from-a-server-to-client-using-asp-net-when-file-size-is-too-big-for-memorystream-using-generic-handlers-ashx/[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 17-Aug-13 14:20pm    
Agree, a 5.
I added some more considerations to it, please see my answer.
—SA
First of all, if this is a Web application, you should not assume that PDF can be rendered on a page at all. PDF is not a part of W3 standards; not all systems and browsers support it, and those which support usually do it via plug-ins which may or may not be installed. (I, for example, don't do it because I'm very dissatisfied with the quality of Adobe viewer, and the viewer I have does not support viewing in browsers, but I does not disturb me at all.)

Now, essentially, for a Web application, there are no "drives". If the PDF file is on the server side, all accessible resources should be under the root directory of the site. A Web application is executed in a sandboxed environment which won't allow access to anything else.

If the PDF file is, by some weird reason, on the client side, yes, there can be "drives" (and not on all systems, only on some), but a Web application does not "know" anything about it at all, so, even though a file can be rendered, nothing can guarantee it.

So, it looks like you should simply abandon the idea and thing of something else. If you explain to us your ultimate goals, you may have a chance to get further advice and what to do. So far, we could only tell you what not to do.

—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