C# .NET - Embedding PDF in a Webpage thats located in another server

Asked By Kishore Rajendran on 06-Jul-11 02:04 AM
I want to display a pdf file in a linkbutton click.
but the problem is the file is located in anotherServer than the website is uploaded.
ie, the website uploaded Server and file existing Server are different.

i searched for this and getting only solution for files located in same drive of website.

can you please help me? thanks
Ravi S replied to Kishore Rajendran on 06-Jul-11 02:22 AM

try this

Create a button like below in your aspx page:

<input type="button" value="Open Pdf" onclick="window.open('openpdf.aspx')" />

Create a aspx page with the name openpdf.aspx, Copy and paste below code on Page_Load of openpdf.aspx

FileInfo fi = new FileInfo(Server.MapPath("yourfile.pdf"));
Response.ContentType =
"Content-Disposition", "inline; filename=" + fi.Name);
"Content-Length", fi.Length.ToString());

Jitendra Faye replied to Kishore Rajendran on 06-Jul-11 02:34 AM

You can use  'embed' tag

Follow these steps-

step1: take one Div with runat="Server" attribute

step 2; Set visible false for Div

Step3: Put onr embed tag with setting all details

step 4: Take one LinkButton

Like this-

<div id="div1" runat="server" style="display:none">
<embed id="showPdf" runat="server" src="location"  type="application/pdf" width="1279" height="630"></embed>

 <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">LinkButton</asp:LinkButton>

Step 5 :

Write this code-

 protected void LinkButton1_Click(object sender, EventArgs e)


Try and let me know.