How to detect if the string indicating a file-system resource is a file or directory

Platform: ASP.NET| Category: Files

VB.NET


Dim path As String = Server.MapPath('webform1.aspx')
’ Put user code to initialize the page here
If(File.GetAttributes(path) And FileAttributes.Directory) = FileAttributes.Directory Then
   	Response.Write('Its a directory')
Else
   	Response.Write('Its a file')
End If

C#


string path =Server.MapPath ('webform1.aspx');
if ((File.GetAttributes(path) & FileAttributes.Directory) ==FileAttributes.Directory)
{
	Response.Write ('Its a directory');
}
else
{
	Response.Write ('Its a file');
}

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.