PC Review


Reply
Thread Tools Rate Thread

Amazing Readonly copy failure

 
 
schaf
Guest
Posts: n/a
 
      24th Jul 2006
Hi NG !
In my first post you requested me to post some sample code.
If I copy a file A (readonly and hidden flag set) and a file B (only
archive flag set) with this code. It would work. Now I would like to do
the same once again. It works because I remove the readonly flag on the
targetFile. But if i set the hidden flag on the targetFile B in the
explorer and run this code once again, an exception would be thrown.
Why ? File A has set the hidden flag to, and the copy process works.
Why not when I change this manually ?

FileInfo backupFile = new FileInfo(sSourceFile);
FileInfo targetFile = new FileInfo(sTargetPath);

//create the target sbudirectory if it does not exist and
copy the file
if (targetFile.Directory.Exists == false)
{targetFile.Directory.Create();}

//Do not copy security backup files, which would not be
deleted by the user.
if
(backupFile.Extension.Equals(sm_sRestoreSecurityExtension) == false) {
//Ensure that no read only flag is set
if (targetFile.Exists == true) {
targetFile.Attributes = targetFile.Attributes ^
FileAttributes.Readonly;
}

//If the readonly flag (in the targetFile) would be set
manually, this command would result in a exception. But why ? Above I
remove this flag!
backupFile.CopyTo(targetFile.FullName, true);
targetFile.Refresh();
FileAttributes targetFileAtt = targetFile.Attributes;
targetFileAtt = targetFileAtt |
FileAttributes.ReadOnly;
targetFile.Attributes = targetFileAtt;
}

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel WB opened from Sharepoint as ReadOnly, ReadONLY for WB = FAL Barb Reinhardt Microsoft Excel Programming 0 19th Jan 2010 10:44 PM
vista ultimate backup failure - shadow copy failure =?Utf-8?B?RGF2ZSBTaHJhZGVy?= Windows Vista General Discussion 4 10th Mar 2008 11:56 AM
vista ultimate backup failure - shadow copy failure =?Utf-8?B?RGF2ZSBTaHJhZGVy?= Windows Vista General Discussion 3 23rd Jul 2007 07:54 AM
Detecting Object type and creating readonly copy at runtime Danielb Microsoft C# .NET 1 31st Jan 2005 02:34 PM
Thoughts on readonly collection of readonly elements emma middlebrook Microsoft C# .NET 0 11th Jan 2004 06:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:53 AM.