Microsoft .NET allows you to read and write files in your
file system provided you have set the necessary permissions. One of the most
powerful things that Microsoft .NET provides you is its rich Base Class Library
that gives you enormous flexibility to do anything that you can think of. The
Base Class Library of the Microsoft .NET Framework class is actually a library
of classes, interfaces that are included as a part of the in the Microsoft .NET
Framework Software Developer's Kit (SDK). A directory is a special type of file
that can contain other files and/or directories. Hence, we will start our
discussion with how we can work with directories in C# followed by a discussion
on how we can use C# to read and write files to and from the file system.
The Directory, DirectoryInfo, File and FileInfo classes in
the .NET Base Class Library provide a simplified and powerful access to the
files and directories in your system.
The names of the members of the Directory, DirectoryInfo,
File and the FileInfo classes are self explanatory. I have shaved off the
unnecessary discussion on the members of these classes that have names that
correspond to their respective purposes. I hoped that the readers would be able
to understand them with ease; still, you can always refer to MSD for more
The following sections discuss each of the above classes and
its members and how they can be used to work with files and directories from
within Microsoft .NET’s managed environment.