Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Zeno Lee
Guest
 
Posts: n/a
#1: Nov 16 '05
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();
}



Zeno Lee
Guest
 
Posts: n/a
#2: Nov 16 '05

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


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.



"Zeno Lee" <zeno_lee@hotmail.com> wrote in message
news:u9Of17w$EHA.2568@TK2MSFTNGP10.phx.gbl...[color=blue]
> 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();
> }
>
>[/color]


Paul E Collins
Guest
 
Posts: n/a
#3: Nov 16 '05

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


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.


Closed Thread