Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide file in C#?

Tags:

c#

.net

I want to hide a file in c#. I know the file path and can create a FileInfo object.

How can I hide it?

like image 915
Rohit Avatar asked Jul 29 '09 11:07

Rohit


People also ask

What is hidden file in C?

In computing, a hidden folder (sometimes hidden directory) or hidden file is a folder or file which filesystem utilities do not display by default when showing a directory listing.

How do I hide private files?

A simple trick for Windows is to merely place your sensitive information within a folder and then mark the folder as 'hidden,' which will hide it within the file explorer. To hide a folder, right click on the folder and select the properties option.


1 Answers

The previously accepted answer:

File.SetAttributes(path, FileAttributes.Hidden); 

will result in certain other attributes it may have being lost, so you should:

File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden); 
like image 51
stovroz Avatar answered Sep 19 '22 10:09

stovroz