1.可以读取文件,将文件在页面显示。
<table style="width: 842px; height: 244px">
<tr>
<td style="width: 100px">
</td>
<td style="width: 100px">
</td>
<td style="width: 100px">
</td>
</tr>
<tr>
<td style="width: 100px">
</td>
<td style="width: 100px">
</td>
<td style="width: 100px">
</td>
</tr>
<tr>
<td style="width: 100px">
</td>
<td style="width: 100px">
</td>
<td style="width: 100px">
<% Response.WriteFile("HTMLPage.htm"); %>
</td>
</tr>
</table>
2.读取文件做下载功能:
private void downloadfile(string fname)
{
if(fname == null || fname.trim() == "")
return ;
fileinfo file = new fileinfo(fname);
response.clear();
response.addheader("content-disposition", "attachment; filename=" + httputility.urlencode((file.name),system.text.encoding.utf8));
response.addheader("content-length", file.length.tostring());
response.contenttype = "application/octet-stream";
response.writefile(file.fullname);
response.flush();
response.close();
response.end();
}
注意: Response.WriteFile和outputcache使用时有些问题。
我们发现在front page 修改了marketing area 的HTML 内容后,front page 不能正常显示。在生成页面的时候它会在marketing area 那部分停止了,浏览器在那个部分因为收不到回应而在那里停止了。我们发现这是因为在同一个页面使用OutputCache 和 Response.WriteFile会发生冲突的情况,在网络上也有人汇报同样的问题。现在page 的解决方法是在 cs 里读取HTML 档案的内容,再写到aspx 的一个literal 里。