System.IO.File.Exists - what if network path and not C:\

  • Thread starter Thread starter Ronald S. Cook
  • Start date Start date
R

Ronald S. Cook

I'm trying to see if a file exists on a server. I have the below code which
doesn't seem to work. Must I necessarily have a mapped drive to that the
path starts with X:\ or similar?

if (System.IO.File.Exists("\\MyServer\MyFolder\MySubFolder\MyFile.txt") ==
true)
{
//Do stuff...
}


Thanks,
Ron
 
Ronald S. Cook said:
I'm trying to see if a file exists on a server. I have the below code
which doesn't seem to work. Must I necessarily have a mapped drive to
that the path starts with X:\ or similar?

if (System.IO.File.Exists("\\MyServer\MyFolder\MySubFolder\MyFile.txt") ==
true)
{
//Do stuff...
}

That code won't compile - you need an @ before the quotes.

Also the == true is not necessary as the Exists method returns true/false
itself
 
That doesn't seem to do it either.


PS said:
That code won't compile - you need an @ before the quotes.

Also the == true is not necessary as the Exists method returns true/false
itself
 
Ronald S. Cook said:
That doesn't seem to do it either.

try...

if (System.IO.File.Exists(@"\\MyServer\MyFolder\MySubFolder\MyFile.txt")) {
// Do Stuff...
}

If this doesn't exist, the user of the process executing this code may not
have read rights for the specified file or....the file may not exist in that
location.

HTH,
Mythran
 
Ahh.. I think that may be it. -thx

Mythran said:
try...

if (System.IO.File.Exists(@"\\MyServer\MyFolder\MySubFolder\MyFile.txt"))
{
// Do Stuff...
}

If this doesn't exist, the user of the process executing this code may not
have read rights for the specified file or....the file may not exist in
that location.

HTH,
Mythran
 
Back
Top