469,319 Members | 2,452 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,319 developers. It's quick & easy.

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

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();
}
Nov 16 '05 #1
2 8658
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" <ze******@hotmail.com> wrote in message
news:u9**************@TK2MSFTNGP10.phx.gbl...
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();
}

Nov 16 '05 #2
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.
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Hal Vaughan | last post: by
1 post views Thread by abcd | last post: by
2 posts views Thread by Andrew J Durstewitz | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.