System.IO.File.Exists behaves differently when run from a mapped drive

Z

Zeno Lee

I'm using File.Exists to test a file on my C: drive.
My program was strongly named and had caspol -af run on it to allow it to
run from the network.

There are 3 ways I am doing this:

1) Run from my C: drive, File.Exists works properly and says
C:\Temp\test.txt exists
2) Run from my H:\ (network) drive, File.Exists says the file doesn't exist.
3) Run from Visual Studio debugger, with project configuration property
working directory set to H:\, File.Exists works properly

What is going on? Does a strongly named exe with caspol run on it behave
differently?


Here's the code below.


[STAThread]
static void Main(string[] args)
{
string _cvs = @"C:\Temp\test.txt";
Console.WriteLine("Current Directory: " +
Directory.GetCurrentDirectory());
if (File.Exists(_cvs))
{
Console.WriteLine(_cvs + " exists.");
}
else
{
Console.WriteLine(_cvs + " doesn't exist.");
}
Console.ReadLine();
}
 
Z

Zeno Lee

It seems File.Exists doesn't make a difference between a File Existing and
having permissions to run the assembly from the network with the improper
security policies.
 
P

Paul E Collins

I think you're seeing the behaviour described here:

"If the caller does not have sufficient permissions to read the
specified file, no exception is thrown and the method returns false
regardless of the existence of path."

P.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top