Breaking News
recent

How to Create A Simple Program For Hiding Folders


Want to hide your folders with a program created by yourself? 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 hide and unhide folders.

We created a Directory info “ch” object which is used to get the properties of a file/folder and then get the file/folder directory. After that, we instantiate the directoryinfo object and assign it to the file/folder directory. Then 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 as shown in the below screenshot.

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

Now double click on  Browse button and copy the below code in:

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

Double click on  Hide button and copy the below code:

try{
ch = new DirectoryInfo(txtFilePath.Text);
ch.Attributes = FileAttributes.Hidden;
MessageBox.Show("Hidden");
}
catch { }

Double click on Open button and copy the below code:

try{
System.Diagnostics.Process.Start(txtFilePath.Text);
}
catch { }

Double click on Unhide button and copy the below code;

try{
ch = new DirectoryInfo(txtFilePath.Text);
ch.Attributes = FileAttributes.Normal;
MessageBox.Show("Visible");
}
catch { }

Then update your Form1.cs with the code given below:

Form1.cs

using System;

using System.IO;

using System.Windows.Forms;

namespace HideFolder

{

public partial class Form1 : Form

{

DirectoryInfo ch;

public Form1()
{

InitializeComponent();

}

private void btnBrowse_Click(object sender, EventArgs e){

if (folderBrowserDialog1.ShowDialog() == DialogResult.OK){

txtFilePath.Text = folderBrowserDialog1.SelectedPath;

}

}

private void btnOpen_Click(object sender, EventArgs e){

try{

System.Diagnostics.Process.Start(txtFilePath.Text);

}

catch { }

}

private void btnHide_Click(object sender, EventArgs e){

try{

ch = new DirectoryInfo(txtFilePath.Text);

ch.Attributes = FileAttributes.Hidden;

MessageBox.Show("Hidden");

}
catch { }

}

private void btnUnhide_Click(object sender, EventArgs e){

try{

ch = new DirectoryInfo(txtFilePath.Text);

ch.Attributes = FileAttributes.Normal;

MessageBox.Show("Visible");

}
catch { }
}

}

}

Now Run your project using F5. Then click on the "Browse a folder" to select the folder you want to hide. Then the folder path will be shown in the textbox. Click on Hide button, the folder will be Hidden and you will get a message

from Scholars Globe - News, Tech, Science, Business... http://ift.tt/2pcv94D
via IFTTT
Oyetoke Toby

Oyetoke Toby

Related Posts:

No comments:

Post a Comment

© CITGuru. Powered by Blogger.