These manipulations are totally naive. You can hide the file or directory, any other code can show it. It does not provide any protection at all. In fact nearly all File Managers routinely provide you with the option to see all the files. Even read-only files are, say, deleted, after just one warning. In this way, manipulations with attributes simply make no sense. You can consider this part of file system functionality "almost" obsolete.
You can do nothing about this unless you use
permissions. You can start from here:
http://msdn.microsoft.com/en-us/library/aa720406%28v=vs.71%29.aspx[
^].
See also this discussion:
http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/c513ca26-9bf8-4e39-a993-4ebf90aaece6/[
^].
However, I would advice not doing it. Messing up with permission and hide anything, taking the risk to leave hidden files forever due to different mistakes? Looks childish. Consider 1) doing everything on an open way, which might be your best choice; 2) using encryption (which is much stronger and more robust then any system tricks taken together, 3) using resources embedded in an executable; 4) using isolated storage if applicable.
On isolated storage, please see:
http://msdn.microsoft.com/en-us/library/3ak841sy.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragefile.aspx[
^],
http://msdn.microsoft.com/en-us/library/cc221360%28v=vs.95%29.aspx[
^].
See also this CodeProject article:
Isolated Storage in .NET to store application data[
^].
—SA