Working with the Server's file system using ASP.NET

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.

- OR -


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

Kevin Marshall

Kevin MarshallI live in Perth, Scotland and am senior programmer with 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.

I have been an avid Dreamweaver user since Version 1 was launched and with the release of MX have moved into developing extensions. WebXeL run a website dedicated to the development of free and commercial Dreamweaver MX extensions for ASP.NET, the site can be found at

See All Postings From Kevin Marshall >>


Misleading: Doesn't work with server file system

July 15, 2010 by Rick Fritz

This entire document describes scenerios working with files located on the local C: drive using System.IO classes and functionality. If you are looking for infomation on how to manipulate "the server's file system" using ASP.NET this will not help you.

You must me logged in to write a review.