This tutorials shows how we can verify if a file exists or not before executing code relating to said file. C# version.

Checking if a file exists before executing certain lines of codes can be very useful. It can prevent error messages caused by trying to manipulate a file that isn’t there, for example. Using System.IO, we can check to see if a file exists in a certain directory with ease.

The ASPX page will look something like this:

The logic will check to see if there is any text in the textbox, when the button is clicked, first and foremost. If there is text present, it will check to see if this text is a file in the media folder. The user will be notified if it exists as a file or not.
The code-behind will look something like this:

Download Source Files