How to use File.Exists?

  • Thread starter Thread starter Steve1 via DotNetMonster.com
  • Start date Start date
S

Steve1 via DotNetMonster.com

Hi all,

I have the below string variable and I am wondering how to check if this file
is present???

string str_Path = @"C:\Documents and Settings\DanielD\My Documents\PLAY AREA\
HLS 2\Layouts£.mdb"

Thanks,
Steve.
 
Steve1 said:
Hi all,

I have the below string variable and I am wondering how to check if this file
is present???

string str_Path = @"C:\Documents and Settings\DanielD\My Documents\PLAY AREA\
HLS 2\Layouts£.mdb"

Thanks,
Steve.

try this:

string str_Path = @"C:\Documents and Settings\DanielD\My
Documents\PLAY AREA\HLS 2\Layouts£.mdb"
System.IO.FileInfo fi = new System.IO.FileInfo(str_Path);
bool exists = fi.Exists;
 
Steve1 via DotNetMonster.com said:
I have the below string variable and I am wondering
how to check if this file is present???

File.Exists is a static method, so you don't need an object. Just
write it as it is.

if (File.Exists(str_Path)) // using your variable name
{
// ... run this code if the file exists ...
}

P.
 
Thanks guys, its appreciated.

File.Exists is a static method, so you don't need an object. Just
write it as it is.

if (File.Exists(str_Path)) // using your variable name
{
// ... run this code if the file exists ...
}

P.
 
Back
Top