Simplified FileAttributes usage with extension methods

Useful extension methods for common used file and folder attributes

In case you are working on a small project where you just store some files and access them, you do not really need a database to achieve accessibility and additional info to files or folders. File-system itself is providing some stuff which can be useful for this. This can seriously reduce the unnecessary logic and complexity of your code and in the end the whole development cycle can be reduced to a really short time.

Recently I worked on a simple application which involves some basic accessibility restriction and rights and I was amazed with what you can done without even using database and have a headache with a second storage beside file-system.

I relied on using file and folder attributes such as readonly and hidden. To make the code simplified I wrote extensions for DirectoryInfo and FileInfo classes.

Since these are static methods, for folders we need to create pretty much the same methods but with a different type of the parameter to which we are applying extension to.

This is just basic set of most commonly used attributes and the ones I used in the above mention application. You can easily extend these extension method static classes to apply additional attributes based on which you can build your logic.



Purpose of the code contained in snippets or available for download in this article is solely for learning and demo purposes. Author will not be held responsible for any failure or damages caused due to any other usage.

About the author


Dejan is a passionate Software Architect/Developer. He is highly experienced in .NET programming platform including ASP.NET MVC and WebApi. He likes working on new technologies and exciting challenging projects

CONNECT WITH DEJAN  Loginlinkedin Logintwitter Logingoogleplus Logingoogleplus


read more


read more

Umbraco CMS

read more


read more

Comments for this article