【发布时间】:2019-06-29 09:05:20
【问题描述】:
我正在尝试创建一个文件/文件夹查看器并下载我将在网页上显示网络共享目录的位置,它将显示共享的所有内容。如果文件是 pdf 或 xls 或 doc,它将被下载,如果它是 HTML,那么它将显示在页面上的 iFrame 中。
我已经完成了第一件事(下载文件),但无法完成第二部分;在 iFrame 中显示 HTML 文件。
当我单击 HTML 文件时,它会像其他文件一样下载,我不确定如何不下载 HTML 文件而是显示在屏幕上。
这个想法是将目录显示为 KB,其中放置了常见问题解答文档或页面。
这是我的下载代码。
Javascript
$('#container_id').fileTree({
root: '<network path to load files from>',
expandSpeed: 1000,
collapseSpeed: 1000,
multiFolder: true
}, function(file) {
$("#iframe").attr("src", "/dl.aspx?file=" + file);
$('#iframe').load();
});
HTML
<div class="example">
<h2>File List</h2>
<div id="container_id" class="demo"></div>
<iframe id="iframe" style="display:none;"></iframe>
</div>
CS
if (Request.QueryString["file"] != null)
{
string actualFilePath = Request.QueryString["file"].ToString();
HttpContext.Current.Response.ContentType = "APPLICATION/OCTET-STREAM";
string filename = Path.GetFileName(actualFilePath);
String Header = "Attachment; Filename=" + filename;
HttpContext.Current.Response.AppendHeader("Content-Disposition", Header);
HttpContext.Current.Response.WriteFile(actualFilePath);
HttpContext.Current.Response.End();
}
【问题讨论】:
标签: javascript html asp.net ajax