?
=?iso-8859-1?Q?Eivind_Gussi=E5s_L=F8kseth?=
Hi!
I'm having trouble executing the FileSystem.CopyFile method because of some
strange behaviour of FileInfo.
The problem occurs when using the constructor of the FileInfo class. I pass
a filename of a file that doesn't exist, but when I check if the file exists
right after creating the FileInfo object, Exists returns True.
Dim vDestinationFile As New FileInfo(vDestinationFileName) ' No file with
this name exists
If vDestinationFile.Exists Then ' This is True, even if the file dosn't
exists on the given location.
....
So when I later try to call FileSystem.CopyFile(vSourceFile.FullName,
vDestinationFile.FullName, True) I get an UnauthorizedAccessException with
message: Access to the path
'C:\Users\Eivind.PROFVET\Documents\TranslationJunk\Clinic\TestTranslationForm.no.resx'
is denied.
I shouldn't have executed this method in the first place, because the True
parameter means that the file vDestionationFile.FullName should be replaced,
but it doesn't actually exist on the harddrive.
When debugging this strange behaviour, I found that
vDestinationFile.Attributes returns value 294. When I look at the
FileAttributes enum, I find that this means the file has the following
attributes:
- Temporary (value 256)
- Archive (value 32)
- System (value 4)
- Hidden (value 2)
These values added gives 294. So my question is: Why does .NET create this
file with those attributes when I use the constructor of FileInfo? I've
never experienced this problem before, even though I've been using the
FileInfo constructor a lot lately. I'm running this program on a Vista 32bit
machine.
I'm having trouble executing the FileSystem.CopyFile method because of some
strange behaviour of FileInfo.
The problem occurs when using the constructor of the FileInfo class. I pass
a filename of a file that doesn't exist, but when I check if the file exists
right after creating the FileInfo object, Exists returns True.
Dim vDestinationFile As New FileInfo(vDestinationFileName) ' No file with
this name exists
If vDestinationFile.Exists Then ' This is True, even if the file dosn't
exists on the given location.
....
So when I later try to call FileSystem.CopyFile(vSourceFile.FullName,
vDestinationFile.FullName, True) I get an UnauthorizedAccessException with
message: Access to the path
'C:\Users\Eivind.PROFVET\Documents\TranslationJunk\Clinic\TestTranslationForm.no.resx'
is denied.
I shouldn't have executed this method in the first place, because the True
parameter means that the file vDestionationFile.FullName should be replaced,
but it doesn't actually exist on the harddrive.
When debugging this strange behaviour, I found that
vDestinationFile.Attributes returns value 294. When I look at the
FileAttributes enum, I find that this means the file has the following
attributes:
- Temporary (value 256)
- Archive (value 32)
- System (value 4)
- Hidden (value 2)
These values added gives 294. So my question is: Why does .NET create this
file with those attributes when I use the constructor of FileInfo? I've
never experienced this problem before, even though I've been using the
FileInfo constructor a lot lately. I'm running this program on a Vista 32bit
machine.