Want to hide your folders with a program you've created? Or have you ever thought of creating a software program that hides folders? If you have, then you are in the right place to learn how to hide folders in C#.
C# makes it easier for you to create a program that simply hides and unhides folders.
We have created a directory info “ch” object which is used to get the properties of a folder and then get the folder directory. After that, we instantiated the directoryinfo object and assigned it to the folder directory. Now, we just change the file attributes of the directory to either Hidden to hide it or Normal to unhide it.
Open Visual Studio, click on New Project -> Windows Form Application and give it any name you want. You can enter "HideFolder" as the name.
Next, add buttons, labels, textbox and folderBrowserDialog to your blank form and design it.
Then, rename the controls as listed below. You can change the properties of controls by clicking on the controls and change the text and name from the Properties dialog box located at the bottom right corner.
Text Name
Browse - btnBrowse
Hide - btnHide
UnHide - btnUnhide
Open- btnOpen
textbox1- txtFilePath
- if (folderBrowserDialog1.ShowDialog() == DialogResult.OK){
- txtFilePath.Text = folderBrowserDialog1.SelectedPath;
- }
- try{
- ch = new DirectoryInfo(txtFilePath.Text);
- ch.Attributes = FileAttributes.Hidden;
- MessageBox.Show("Hidden");
- }
- catch { }
- try{ System.Diagnostics.Process.Start(txtFilePath.Text); } catch { }
- try{
- ch = new DirectoryInfo(txtFilePath.Text);
- ch.Attributes = FileAttributes.Normal;
- MessageBox.Show("Folder Visible");
- } catch (Exception ex){MessageBox.Show("Error Occured due to" + ex); }
Then, update your Form1.cs with the code given below.

Osama AlnaifPosted Oct 21, 2022, 1:07 PM
Hiding file folder using "attribute" commands can be reversed by user.
International HdPosted Jul 31, 2019, 2:51 AM
After close app ,,how to unlock that file ,,,history code
KLOP ConanPosted Jun 10, 2019, 11:07 PM
Missing one line in this code: FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();