views:

384

answers:

2

I have created a folder lock in C#.NET which is working good on NTFS file system But its not working on FAT file system. please tell which dll/class/namespace should i use to get Lock files and folder on FAT file system through C#.NET

sample code which is working with NTFS (below code is to unlock file/folder)

FileInfo info = new FileInfo(folderpath);
FileSecurity accessControl = info.GetAccessControl(AccessControlSections.All);
accessControl.RemoveAccessRule(
    new FileSystemAccessRule(
        Environment.UserName.ToString(), 
        FileSystemRights.FullControl, 
        AccessControlType.Deny));

accessControl.SetSecurityDescriptorSddlForm(
    "D:(A;;GAGRGWGXRCSDWDWORPWPCCDCLCSWLODTCR;;;WD)", 
    AccessControlSections.All);
info.SetAccessControl(accessControl);
+2  A: 

You cannot. The FAT file system does not support many advanced features, such as access control lists. (Basically the only feature resembling access control in FAT is the "read only" file attribute bit, which applies to every user)

intgr
I have seen a program created in Delphi which is able to lock folder and files in FAT file system. please give me idea from witch i can do it (may through other way)
Rajesh Rolen- DotNet Developer
"File locking" has **nothing to do with access controls;** rather it's analogous to mutexes on a file system (see http://en.wikipedia.org/wiki/File_locking). Since this is implemented in the operating system's VFS layer, it's available with every file system.
intgr
Can u tell me how can i access VFS Layer in C#.NET and lock folders and file on FAT file system
Rajesh Rolen- DotNet Developer
File locks **are not a security feature**. But if you insist, it goes something like this: `FileStream fs=new FileStream("c:\\Variables.txt", FileMode.Append, FileAccess.Write, FileShare.Write);` -- opens the file and locks it in write-exclusive mode (`FileShare.Write`); the lock is released when you close this file
intgr
no i dont want this.I want a strong security system for files and folders. please give me suggestion
Rajesh Rolen- DotNet Developer
Jeez, I told you. FAT does not offer security. If you want access control, do not use FAT.
intgr
A: 

The FAT file system does not support security so you are not able to set ACLs in the way you illustrate in your question.

More details can be found at Wikipedia

HakonB