This tutorial explains how to carry out many common tasks relating to the accessing and manipulating a server file system, including listing files and directories, checking for the existence of a specific file or directory, reading and writing text to text files, copying, moving and deleting files and directories. You will also be shown how to obtain statistics of directories and files such as file size and modified dates. By the time you have worked through this article you will be more knowledgeable about file system access and manipulation using the powerful classes provided within the .NET Framework.
The tutorial covers the following subjects:
- Writing text to a file
- Reading text from a file
- Finding out if a file or directory exists
- Renaming a file or directory
- Copying and moving a file or directory
- Deleting a file or directory
- Listing the contents of a directory
- A hierarchal listing example
- Common problems and errors
We end the tutorial with an example of displaying the contents of a directory using a recursive routine to show the hierarchy of its contents in much the same manner as a tree control would display them.
Overview
Table of Content:
- Common problems and errors
- About the .NET file classes
- Creating and writing text to a file
- Write text to an existing file
- Read text from a file
- Find out if a file or directory exists
- Rename a file or directory
- Moving a file or directory
- Copying a file
- Delete a file or directory
- Get file or directory statistics
- List the contents of a directory
- A hierarchal listing example
I live in Perth, Scotland and am senior programmer with WebXeL.com Ltd. I have been involved in computer programming since 1990, web based programming using ASP since 1997 and have been building ASP.NET applications since ASP.NET Beta 2 was released.



