Click here to Skip to main content
15,900,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can anyone help me about this problem ? I have try DirectoryInfo to set attributes to folder.

DirectoryInfo dir=new DirectoryInfo(path)
dir.Attributes=File.Attributes.ReadOnly

But it work only with emty folder. How would i do ????
( Sorry for my bad english)
Posted

1 solution

You have to OR it into it like this:

C#
var di = new DirectoryInfo("SomeFolder");
di.Attributes |= FileAttributes.ReadOnly;


Good luck!
 
Share this answer
 
v2
Comments
ngocthanhcr 29-Jul-10 9:50am    
Thanks. It's work perfectly. But may I ask some question ?
I try to show the folder i have set attributes to " hidden " by window explorer ( I set folder option " Show hidden Folder and Files") but window explorer did not show the folder. After that, I use total commander , and i can see it. Can you explain to me why ?
E.F. Nijboer 29-Jul-10 13:18pm    
Maybe it's a system file? There is a different option for that in explorer. The other option is that you have explorer already open, run your program and change the attribute but needed to press F5 to refresh explorer and see the change.
ngocthanhcr 30-Jul-10 6:27am    
Thanks a lot for your answer
E.F. Nijboer 30-Jul-10 7:52am    
Just for the record... which of the two was the reason for the file not showing? :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900