如何在iframe中显示来自特定文件夹的PDF? [英] How to show PDF in iframe from a specific folder?
问题描述
我有2个链接按钮.我的代码正在运行:
protected void LinkButton1_Click(object sender, EventArgs e)
{
myframe.Attributes["src"] = "LINQToSQLCheatSheet.pdf";
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
myframe.Attributes["src"] = "20120517110052.pdf";
}
<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">Pdf 1</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" onclick="LinkButton2_Click">pdf 2</asp:LinkButton>
<div style="width:100%; height:850px">
<iframe id="myframe" width="100%" height="100%" runat="server"></iframe>
但是,当我将这2个pdf文件保存在一个文件夹中时,这是行不通的.将pdf文件放入文件夹后的代码:
But, when I am keeping these 2 pdf files in a folder than this is not working. My code after putting pdf files in a folder:
protected void LinkButton1_Click(object sender, EventArgs e)
{
myframe.Attributes["src"] = "Folder:\\LINQToSQLCheatSheet.pdf";
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
myframe.Attributes["src"] = "Folder:\\20120517110052.pdf";
}
现在,我收到一条错误消息:
"Firefox不知道如何打开此地址,因为协议(文件夹)未与任何程序关联.
您可能需要安装其他软件才能打开此地址."
我已经在另一个过程中尝试过,例如:
Now, Im getting a error message:
" Firefox doesn''t know how to open this address, because the protocol (folder) isn''t associated with any program.
You might need to install other software to open this address."
I have tried it in another process as like this:
protected void LinkButton1_Click(object sender, EventArgs e)
{
myframe.Attributes["src"] = "\Folder:\\LINQToSQLCheatSheet.pdf.pdf";
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
myframe.Attributes["src"] = "\Folder:\\20120517110052.pdf.pdf";
}
现在出现另一个错误:
无法识别的scape序列"
现在,有人可以解决此问题,因为我必须显示文件夹或其他目录中的pdf文件.
Now getting another error:
"Unrecognized scape sequence"
Now, can anybody help me by solving this problem as I have to show those pdf file from a Folder or another directory.
推荐答案
您需要在路径的开头放置一个\,以便找到文件.
You need to put a \ in the start of the path, in order for it to find the file.
在您的开始处使用"@"路径,然后给出整个路径;
喜欢
Use ''@'' at the start of your Path,and after that give your whole path;
Like
myframe.Attributes["src"] = @"Folder:\20120517110052.pdf";
试试这个.
Try this.
这篇关于如何在iframe中显示来自特定文件夹的PDF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!