pvaju896
pvaju896

Reputation: 1417

creating hidden files using .NET

How can I create or mark a file as hidden using .NET?

Upvotes: 3

Views: 11266

Answers (4)

stovroz
stovroz

Reputation: 7065

If it's an existing file, i.e. not one you've just created, don't just:

File.SetAttributes(path, FileAttributes.Hidden);

or certain other attributes it may have will be lost, so rather you should:

File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden);

Upvotes: 2

Oded
Oded

Reputation: 498914

You set the hidden attribute of the file.

There are several ways of doing so - with File.SetAttributes or FileInfo.Attributes, you simply set the FileAttributes enumeration flag to hidden:

string path = @"c:\myfile.txt";
File.SetAttributes(path, FileAttributes.Hidden);

Upvotes: 12

airmanx86
airmanx86

Reputation: 1002

I assume you are referring to setting the file attribute to hidden in the file system. Please take a look at this link

Upvotes: 5

Jacob
Jacob

Reputation: 78850

Use File.SetAttributes. "Hidden" is just one of many available attributes.

Upvotes: 17

Related Questions