Wednesday, November 24, 2010

Reading and Writing in Asp.Net using C#

Reading and writing into file content using ASP.NET and C# is very simple.

First, you will need to import the System.IO namespace.

using System.IO;

The System.IO namespace contains types that allow reading and writing to the files and data streams, and types that provide basic file and directory support.

Use the DirectoryInfo Class for operations such as copying, moving, renaming, creating and deleting directories.

Use The File Class for operations such as creating, opening, deleting, appending, copying, moving and renaming files.

Use The ReadAllText method to open a text file, reads all the lines of file and then closes the file.

Use The WriteAllText method to create a new file, writes the specified string to the file and then closes the file. If target file already exists, it will be overwritten.

No comments:

Post a Comment