The below C# code will help to append the new attributes to a file without deleting the existing attributes. for example the below code add the hidden attribute to file Demo_File.txt.
Source Code:
using System;
using System.IO;
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
string txt_file = @"c:\Demo_File.txt";
bool is_Hidden = ((File.GetAttributes(txt_file) & FileAttributes.Hidden) == FileAttributes.Hidden);
Console.WriteLine("Hidden Attribute Before Append: " + is_Hidden.ToString());
File.SetAttributes(txt_file, File.GetAttributes(txt_file) | FileAttributes.Hidden);
is_Hidden = ((File.GetAttributes(txt_file) & FileAttributes.Hidden) == FileAttributes.Hidden);
Console.WriteLine("Hidden Attribute After Append: " + is_Hidden.ToString());
Console.ReadLine();
}
}
}
No comments:
Post a Comment