Click here to Skip to main content
15,880,405 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi there!
How can i create a folder with a password protection?

I can create a folder with:

C#
Directory.CreateDirectory(path);


But how can I protect the folder with a password?
Posted

 
Share this answer
 
Comments
Ron Beyer 17-Jan-14 13:59pm    
This only works if the person is a member of a domain with AD services.
Password protected folders are not a feature of Windows. In order to restrict access you need to use something called Access Control Lists (ACLs). There are a few built-in classes to help with this, like FileSecurity[^] and DirectorySecurity[^] but both require that you assign security to existing users. It will not keep somebody logged in who has permissions to open the folder from opening it without entering the password.
 
Share this answer
 
v3
Actually Ron Beyer is right. Still, if you want to hide something from the administrator too, than that won't work.

You can use (A) EFS[^] from code: http://msdn.microsoft.com/en-us/library/system.io.file.encrypt(v=vs.110).aspx[^] or create encrypted content (B): http://support.microsoft.com/kb/307010[^].
This later works for individual files only. Adding proper ACLs could hide files from non-authorized normal users, but neither the administrator can read the content. Be aware, that EFS is bound to the user on that system, so you have to think trough: https://support.microsoft.com/kb/223316[^]

But you can use also something like 7-zip's API (C) (see: http://sevenzipsharp.codeplex.com/[^]) to create encypted "folders". You can even combine ziping and encrypting the filestream itself (D).

But only (A) and (C) will enable the authorized users to access the content with applications others than yours.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900