Saravanan
Saravanan

Reputation: 11592

couldn't display pdf file in my iframe in .net web application?

I have to display a pdf file in an iframe control in .net web application.But when I run the application it could not load the pdf file in an iframe control. I don't know the reason for this...

This is my code...

aspx code :

<iframe id="frmWord" runat="server" style="height: 500px; width: 500px;"></iframe>

C# Code :

protected void Button1_Click(object sender, EventArgs e)
{
    frmWord.Attributes.Add("src", Server.MapPath(@"~/iplt20.pdf"));
}

my pdf file is physically located in my project folder like below:

D:\vs-2010projects\rti_chk\rti_chk\iplt20.pdf

I have tried in ie,firefox,chrome also...

If firefox, inside iframe control it says "The address wasn't understood Firefox doesn't know how to open this address, because the protocol (d) isn't associated with any program."

Please guide me to get out of this issue...

Upvotes: 0

Views: 1607

Answers (1)

adt
adt

Reputation: 4350

User cannot drectly access local paths on server.

instead of d:\path_to_file you should produce something like http://youdomain.com/path-to_file

so

protected void Button1_Click(object sender, EventArgs e)
{
    var fullPath = ResolveUrl(filePath); // this could work instead of string concat
    //var fullPath = String.Format("{0}/{1}",serverpath,filepath);
    frmWord.Attributes.Add("src", fullPath);
}

Upvotes: 1

Related Questions