Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
286 views
in Technique[技术] by (71.8m points)

.net - How to hide file in C#?

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

How can I hide it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...