views:

437

answers:

5

In my code i do

    if (!File.Exists(getSomePath()))
    {
        MessageBox.Show("... existing" + " " + getSomePath());
        this.Close();
    }

I can see getSomePath() is correct but when i open the app on the network it says it doesnt exist. When i copy the folder to my local drive it says it does exist. Whats going on?

A: 

You've the two confused.

hmcclungiii
what do you mean?
roman m
this confused me!
proudgeekdad
+1  A: 

You mention that it works ok locally, but not when you run it from a network share. Does your application have the appropriate security permissions to access the filesystem? By default, applications run from a network share have reduced security permissions.

Turnor
+1  A: 

File.Exists most anywhere is suspect. But when you do go to open the file, this sounds like a network permissions issue.

Joel Coehoorn
+2  A: 

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.

roman m
From my own testing, this doesn't seem to be the case.
Turnor
what "doesn't seem to be the case"?
roman m
When you run a .NET application from a network share rather than a local drive, it runs in the security context of that share, but it doesn't mean that C:\ refers to that network share. C:\ still refers to the local drive.
Turnor
got it, thanx for clarification
roman m
+1  A: 

If you're running it from a network share, then you will need to have the users add the compiled assembly as trusted in the .net. The way to do this is by "strong naming" your assembly, and having that strong name trusted on each user's computer.

Edit: The reason for this is for security, so a unwary user doesn't get a virus that runs from a remote (network share, etc) location. This only occurs when the user is running the app that lives in the remote location. He can neither access file shares or even his own local system from that remote app.