【发布时间】:2011-01-06 12:43:38
【问题描述】:
我想在我的页面中包含某些文件。 我并不总是确定它们是否存在,所以我必须检查它们是否存在。 (否则页面会崩溃,你可能知道)
<%@ Page Language="C#" %>
<html>
<body>
<% bool exists;
exists = System.IO.File.Exists("/extra/file/test.txt");
%>
Test include:<br>
<!--#include file="/extra/file/test.txt"-->
</body>
</html>
</html>
虽然包含有效,但检查文件是否存在的代码无效。
如果我删除此代码:
<% bool exists;
exists = System.IO.File.Exists("/extra/file/test.txt");
%>
一切运行良好。
我也尝试将其放入<script runat="server"> 块中,但仍然失败。
【问题讨论】:
标签: c# asp.net include file-exists