Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

c# how to create secure folder (password protected)

$
0
0

I Want to create secure folder..Client will not able to open my folder.

i research and find below code...

but this code not help me because i can change easily and allow user to open by properties

option and go advance button here my current user i edit permission deny to allow...this is not secure way

to create folder...please help me to create secure so client fully 100% not able to open folder

using System;using System.IO;using System.Security.AccessControl;namespace FileSystemExample {class DirectoryExample {publicstaticvoid Main() {try {string DirectoryName = "TestDirectory"; Console.WriteLine("Adding access control entry for "+ DirectoryName);// Add the access control entry to the directory. AddDirectorySecurity(DirectoryName, @"MYDOMAIN\MyAccount", FileSystemRights.ReadData, AccessControlType.Allow); Console.WriteLine("Removing access control entry from "+ DirectoryName);// Remove the access control entry from the directory. RemoveDirectorySecurity(DirectoryName, @"MYDOMAIN\MyAccount", FileSystemRights.ReadData, AccessControlType.Allow); Console.WriteLine("Done."); }catch (Exception e) { Console.WriteLine(e); } Console.ReadLine(); } // Adds an ACL entry on the specified directory for the specified account. publicstaticvoid AddDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType) {// Create a new DirectoryInfo object. DirectoryInfo dInfo = new DirectoryInfo(FileName);// Get a DirectorySecurity object that represents the  // current security settings. DirectorySecurity dSecurity = dInfo.GetAccessControl();// Add the FileSystemAccessRule to the security settings. dSecurity.AddAccessRule(new FileSystemAccessRule(Account, Rights, ControlType));// Set the new access settings. dInfo.SetAccessControl(dSecurity); } // Removes an ACL entry on the specified directory for the specified account. publicstaticvoid RemoveDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType) {// Create a new DirectoryInfo object. DirectoryInfo dInfo = new DirectoryInfo(FileName);// Get a DirectorySecurity object that represents the  // current security settings. DirectorySecurity dSecurity = dInfo.GetAccessControl();// Add the FileSystemAccessRule to the security settings. dSecurity.RemoveAccessRule(new FileSystemAccessRule(Account, Rights, ControlType));// Set the new access settings. dInfo.SetAccessControl(dSecurity); } }

      

qasim


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>