Able to include file in ASP.NET, but not check if it exists <p>I want to include certain files in my page. I'm not always sure if they exists, so I have to check if they do. (Otherwise the page crashes, as you probably know)</p> <pre><code>&lt;%@ Page Language="C#" %&gt; &lt;html&gt; &lt;body&gt; &lt;% bool exists; exists = System.IO.File.Exists("/extra/file/test.txt"); %&gt; Test include:&lt;br&gt; &lt;!--#include file="/extra/file/test.txt"--&gt; &lt;/body&gt; &lt;/html&gt; &lt;/html&gt; </code></pre> <p>While the include works, the code checking if the file exists does not.</p> <p>If I remove this code:</p> <pre><code>&lt;% bool exists; exists = System.IO.File.Exists("/extra/file/test.txt"); %&gt; </code></pre> <p>Everything runs fine. I also tried putting it in a <code>&lt;script runat="server"&gt;</code> block, but it still failed.</p>