c# check if path exists

Hi guys,

So many a times we have this situation where we know user can input path as a directory or a path to file itself.


Now in those circumstances we want to check if the path to directory or file is valid or not.

Generally you can do it in several ways and make things as complex as possible.

Below is a function that I use to find out if supplied path Exists or not


You can also use File.Exists to check if the file exists


to check if the path is a directory.


You will be interested in reading this post written by me to find out if the supplied path is a path to Directory or path to File. Read it here


I hope this helps.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.