Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
File.Exists(string path) misbehavior
Message
General information
Forum:
ASP.NET
Category:
Other
Environment versions
OS:
Windows 2000
Miscellaneous
Thread ID:
01009851
Message ID:
01010247
Views:
30
Einar,

Thanks for taking the time to look at this.

I can run it all day without problems, so long as the files are all actually where they are supposed to be. I have checked for silly mistakes. If I run it for 5 files, it works fine. If I run it again on the same 5 files and remove the third file, the first two are copied, the third one doesn't exist and isn't copied, but then the fourth and fifth ones are reported as non-existent.

I hate to add an additional ugly detail, but this code is part of a Windows service and the code below occurs inside an impersonation context. I really didn't want that to matter, but maybe I should mention it in case it does. The impersonation context is wrapped around the file transfer only.

If the service is restarted after one file is reported non-existent, it does not mistakenly report existent files as not existing. I wonder if, somehow, the static File object is getting stuck and if I could force .NET to destroy the File object and recreate it every time a file didn't exist, that would be a decent workaround.

Can I force the destruction of a static object by calling the destructor, somehow?



>David,
>I tried running the code you posted and I do not see the behavior that you describe. I am not running this over a Novell network. Have you tried stepping through the code in the debugger to make sure there isn't something silly going on (like a missing slash in the path or a filename without ext).
>I must agree with you that I find it hard to belive that M$ has a bug like this in their File class. Hopefully someone else will be able to test your code against a Novell server.
>
>Einar
>>I am having a problem using File.Exists.
>>
>>I want to copy files from a remote server to a local directory on a Novell Network between two windows machines. I create a string array containing filenames from a database query.
>>
>>I am using File.Exists to first ensure the file exists and then copy it locally. After the first time File.Exists returns false, it returns false thereafter for the existing files that I check, even though I can see they exist using Windows Explorer.
>>
>>I have done the obvious things, like trying to check different numbers of existing files before checking my first non-existent one, and making sure that the paths are correct. If I restart my program, the problem goes away until File.Exists returns false for the first time again.
>>
foreach (string filename in fileNameArray)
>>{
>>    remoteFilename = RemoteDirectory + filename;
>>    localFilename =  LocalDirectory + filename;
>>    if(File.Exists(remoteFilename))
>>    {
>>        // Copy file to local directory
>>        File.Copy(remoteFilename, localFilename, false);
>>    }
>>}
>>I was originally just making the copy attempt in a try-catch block without checking for the file's existence, but the problem kept occuring: after trying to copy one non-existent file and getting a FileNotFoundException, it threw FileNotFoundExceptions for all following files I tried to copy, even though they existed.
>>
>>It's hard to believe it's a bug in the .NET File object. I tried using the FileInfo object, since it isn't static, hoping that by recreating a FileInfo object every time I checked for file existence, whatever was "stuck" false would be unstuck. It didn't work.
>>
>>If account permissions are lacking, File.Exists returns false even if the file is there. The only non-bug problem that I can think of is that our network security policy is trying to prevent file snooping by removing privileges from an account that looks for non-existent files. We use Novell networking, but I don't know the version. I can ask our network admin about this possibility on Monday.
>>
>>Does anyone have any other idea about what the problem might be? The fact that it goes away after I restart the program leads me to believe that the static File object is destroyed and the problem is fixed and perhaps FileInfo is just a non-static wrapper around File.
>>
>>Thanks for any ideas that anyone has.
David S. Alexander
Kettley Publishing
20271 SW Birch Street, 2nd Floor
Newport Beach, CA 92660-1752
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform