Home > Backend Development > C#.Net Tutorial > How to open hidden files using C#?

How to open hidden files using C#?

WBOY
Release: 2023-09-06 13:33:06
forward
1070 people have browsed it

How to open hidden files using C#?

To open a hidden file, make it visible first. You can do this by removing the hidden attributes set on it -

FileInfo file= new FileInfo(Environment.CurrentDirectory + @"\myFile.txt");
file.Attributes &= ~FileAttributes.Hidden;
Copy after login

Now treat it as a normal text file and open it. Read the content -

using (StreamReader sr = new StreamReader("myFile.txt")) {
   string line;

   while ((line = sr.ReadLine()) != null) {
      Console.WriteLine(line);
   }
}
Copy after login

After reading, set the properties to hidden again to hide the file -

file.Attributes |= FileAttributes.Hidden;
Copy after login

The above is the detailed content of How to open hidden files using C#?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template