ページに特定のファイルを含めたい。それらが存在するかどうかは常にわからないので、存在するかどうかを確認する必要があります。(そうしないと、ご存知のようにページがクラッシュします)
<%@ 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">
が、やはり失敗。