The only way to prevent the user from deleting a folder is by having a file in that folder opened by a process (I think setting a file in the folder to be read only may also work).
Caveat: When you delete a folder, the file system first tries to delete files in the folder, and when all of them are deleted, it tries to delete the folder. It deletes files in the order they were written to the disk, so it might delete other files BEFORE it gets to the file that will prevent the file system from deleting the folder.
Example added (ManfredRBihy):
StreamWriter sw = null;
StreamWriter firstSW = null;
for (int idx = 0; idx < 10; idx++)
{
String fileName = String.Format("C:\\temp\\Manfred\\subfolder\\{0}.txt", idx);
sw = new StreamWriter(File.Open(fileName, FileMode.Create));
sw.Write(fileName);
if (idx == 0)
firstSW = sw;
else
{
sw.Close();
sw.Dispose();
}
}
Console.WriteLine("Writing all files finished");
Console.WriteLine("Deletion of folder will fail. Hit enter!");
Console.ReadLine();
firstSW.Close();
firstSW.Dispose();
Console.WriteLine("Deletion of folder will now succeed! Hit enter");
Console.ReadLine();
End of Example