-3

I am working on an application that requires that some files are copied to a different folder. I use the following:

DirectoryInfo dir = new DirectoryInfo(path);

foreach (FileInfo filesindires in dir.GetFiles())
{
  FileSecurity ds = filesindires.GetAccessControl();
  ds.AddAccessRule(new FileSystemAccessRule("Authenticated Users", 
                   FileSystemRights.FullControl, AccessControlType.Deny));
  filesindires.SetAccessControl(ds);
}

With that method I deny the user from opening the file, but I would like to only prevent copying. How can I prevent that a file is copied while allowing the user to read it?

HaskellElephant
  • 9,819
  • 4
  • 38
  • 67
BOSS
  • 1,828
  • 11
  • 34
  • 60
  • There's no real difference between opening a file to read it and opening a file to copy it - both are going to read the data. The only difference is that a copy operation tends to write the data back out to another file. – Marc B Oct 31 '11 at 19:33
  • How to set permissions programmatically would be on topic here, but this question is how to choose permissions and that has nothing to do with programming. – Ben Voigt Oct 31 '11 at 19:34
  • If you can read the contents of the file you can copy it. Copy is simply creating a new file and duplicating the name, attributes, and contents of the file. – user957902 Oct 31 '11 at 19:34
  • Lol! If it was possible noone would get so angry and crazy about piracy :) – Salvatore Previti Oct 31 '11 at 20:11

1 Answers1

1

If you can read it, you can copy it.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720