PC Review


Reply
Thread Tools Rate Thread

How can I set files read only?

 
 
jmDesktop
Guest
Posts: n/a
 
      27th Oct 2008
I know I can use FileAttributes.Normal but it doesn't always work. I
am using the FileSystemWatcher class. I have found that if I uncheck
the read-only flag from the directory and apply to all sub folders and
files the check will go away on the file. If I use the class it never
gets unset. I wanted to know if there was a way to activate the
uncheck apply to all programatically. thanks
 
Reply With Quote
 
 
 
 
Jeroen Mostert
Guest
Posts: n/a
 
      27th Oct 2008
jmDesktop wrote:
> I know I can use FileAttributes.Normal but it doesn't always work. I
> am using the FileSystemWatcher class. I have found that if I uncheck
> the read-only flag from the directory and apply to all sub folders and
> files the check will go away on the file. If I use the class it never
> gets unset. I wanted to know if there was a way to activate the
> uncheck apply to all programatically. thanks


FileSystemWatcher, as the name implies, watches. It can't be used to alter
file attributes, so I suspect you're confusing two things.

There is no built-in method for marking a directory and all subdirectories
and files as not read-only. You can manually walk the file system with (for
example) DirectoryInfo.GetFileSystemInfos() and reset the readonly attribute
yourself with .Attributes = .Attributes & ~FileAttributes.ReadOnly. Consult
the MSDN for more info on how to reset flags.

If, on the other hand, you just want to be informed when a file's attributes
change, then FileSystemWatcher could be used. You should set
..IncludeSubdirectories to true and .NotifyFilters to
NotifyFilters.Attributes to watch all files. Take note that this can
generate a large number of events.

If, on the gripping hand, you want to reset the readonly attribute of a file
you're watching with a FileSystemWatcher, first create a FileInfo instance
to it using the .FullName property of the FileSystemEventArgs you have, then
reset the readonly attribute in the manner described above.

If none of this should happen to apply, you'll have to be more specific.

--
J.
 
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
turning Read Only files into Read/Write with Paul Microsoft Access Forms 2 25th Sep 2009 12:29 AM
Folders/files read only/can't create new folder in read only folde =?Utf-8?B?Z3NoaWxsaXRhbmk=?= Windows Vista Administration 8 25th Sep 2007 01:50 PM
How to find all files in a subdirectory read which are writable (=not read-only) ? Tim Tuples Windows XP General 4 23rd Jan 2005 01:18 PM
How to find all files in a subdirectory read which are writable (=not read-only) ? Tim Tuples Windows XP Help 0 18th Jan 2005 08:13 PM
Read only files to read-write files. Tried unclicking the box, di. =?Utf-8?B?ZGF3bnlraW5z?= Microsoft Excel Misc 4 2nd Nov 2004 04:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:59 AM.