www.jlion.com

Monday, December 05, 2005

I've just run into an odd problem when attempting to overwrite exiting files using VB.NET and the File.Copy function. When I do this I get a System.UnauthorizedAccessException.

A bit of research revealed that the files being overwritten had their read-only attribute set, so I was able to use the following code to remove the read-only attribute before overwriting the file.

'---Make sure file exists and has READONLY attribute set. If it does, flip READONLY attribute.
If File.Exists(sInstallDescriptionFile) = True AndAlso (File.GetAttributes(sInstallDescriptionFile) And FileAttributes.ReadOnly) Then
File.SetAttributes(sInstallDescriptionFile, File.GetAttributes(sInstallDescriptionFile) Xor FileAttributes.ReadOnly)
End If

File.Copy(sSourceFullName, sDestinationFullName, True)

1 Comments:

Blogger lucyharolds2347 said...

This post has been removed by a blog administrator.

5:32 AM  

Post a Comment

<< Home