Hello Everyone....!!! This is Kabeer Hussain....



In this article you will learn how to create simple folder lock windows based software in C#.net...
This software have Four(4) main funtionalities
1: Lock Folder
2: Unlock Folder
3: Hide Folder
4: Unhide Folder

We will talk about the funtionalities one by one...

1: Lock Folder:

                      Drag and Drop a button from toolbox and change the name property to btnLock and                             change the text also with Lock.
                      Then double click the button and copy paste the code given below..
   
        Code:
           
                 if (txtFilePath.Text.Length > 0)
            {
                try
                {
                    string folderPath = txtFilePath.Text;
                    //Lock1.Text = txtFilePath.Text;
                    string adminUserName = Environment.UserName;// getting your adminUserName
                    DirectorySecurity ds = Directory.GetAccessControl(folderPath);
                    FileSystemAccessRule fsa = new FileSystemAccessRule(adminUserName,                                           FileSystemRights.FullControl, AccessControlType.Deny);
                    ds.AddAccessRule(fsa);
                    Directory.SetAccessControl(folderPath, ds);
                    MessageBox.Show("Locked");
                }

                catch
                {
                }
            }

Unlock :

                       Drag and Drop a button from toolbox and change the name property to btnUnlock and                            change the text also with Unlock.
                      Then double click the button and copy paste the code given below..

     Code:
             if (txtFilePath.Text.Length > 0)
            {
                try
                {
                   // Lock1.Text = "";
                    string folderPath = txtFilePath.Text;
                    string adminUserName = Environment.UserName;// getting your adminUserName
                    DirectorySecurity ds = Directory.GetAccessControl(folderPath);
                    FileSystemAccessRule fsa = new FileSystemAccessRule(adminUserName, FileSystemRights.FullControl, AccessControlType.Deny);
                    ds.RemoveAccessRule(fsa);
                    Directory.SetAccessControl(folderPath, ds);
                    MessageBox.Show("Unlocked");
                }
                catch
                {
                }
            }
             

Hide:

                       Drag and Drop a button from toolbox and change the name property to Hide and                                  change the text also with Hide.
                      Then double click the button and copy paste the code given below..

         Code:
       
                   ch = new DirectoryInfo(txtFilePath.Text);
            //Hide1.Text = txtFilePath.Text;
            ch.Attributes = FileAttributes.Hidden;
            MessageBox.Show("Hidden");





UnHide:

                       Drag and Drop a button from toolbox and change the name property to Unhide and                                  change the text also with Unhide.
                      Then double click the button and copy paste the code given below..

         Code:
       
                   //Hide1.Text = "";
                  ch = new DirectoryInfo(txtFilePath.Text);
                  ch.Attributes = FileAttributes.Normal;
                  MessageBox.Show("Visible");




Hide:

                       Drag and Drop a button from toolbox and change the name property to Unhide and                                  change the text also with Unhide.
                      Then double click the button and copy paste the code given below..

         Code:
       
                   //Hide1.Text = "";
                  ch = new DirectoryInfo(txtFilePath.Text);
                  ch.Attributes = FileAttributes.Normal;
                  MessageBox.Show("Visible");


Hide:

                       Drag and Drop a button from toolbox.
                      Then double click the button and copy paste the code given below..

         Code:
       
                   if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                txtFilePath.Text = folderBrowserDialog1.SelectedPath;
            }


Text Box:
                 Drag and Drop textbox with name property txtfilePath .

         



Coded By: Kabeer Hussain Shigri

Comment Below if You have any problem ...
SHARE
    Blogger Comment
    Facebook Comment

1 comments: