File Hiding
-
Hi , I want to hide a file after creating it in C# by using File class and also to hide it .After creating it using File class's create method when I use File class's set attribute and set the attribute of file to hidden and readonly ,only readonly is getting set but the file is not getting hidden.What to do?
-
Hi , I want to hide a file after creating it in C# by using File class and also to hide it .After creating it using File class's create method when I use File class's set attribute and set the attribute of file to hidden and readonly ,only readonly is getting set but the file is not getting hidden.What to do?
Prashant Gadhave wrote:
What to do?
Start by showing the code you are using to change the attributes as that is likely to be where you have made the mistake. Im guessing you've tried to set each attribute separately, not realising that it is a bitmask value - thus overwriting the hidden attribute with readonly. Current blacklist svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
-
Prashant Gadhave wrote:
What to do?
Start by showing the code you are using to change the attributes as that is likely to be where you have made the mistake. Im guessing you've tried to set each attribute separately, not realising that it is a bitmask value - thus overwriting the hidden attribute with readonly. Current blacklist svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
What J4amieC said is probably exactly what's happening... If you want to set it all in one shot you can use:
File.SetAttributes(@"C:\test.txt", FileAttributes.Hidden | FileAttributes.ReadOnly);
If you want to add another attribute onto a file you need to add to the "existing" attributes, for example:
FileAttributes attr = File.GetAttributes(@"C:\test.txt");
File.SetAttributes(@"C:\test.txt", attr |= FileAttributes.Hidden);Hope that helps..