Check the given Path is of a File or a Directory

Below sample code will help you How to check the given path is of a File or a Directory?

Add below namespace on your page,
using System.IO;

Solution :
string path = @"C:\Test.xml";
if (File.Exists(path))
{
      Response.Write(path + " is a File.");
}
else if (Directory.Exists(path))
{
      Response.Write(path + " is a Directory.");
}

No comments:

Post a Comment