Reader Level:

Write to a File in C#

On August 06, 2012 Articles | C# Programming
In this article we will discuss about how to write to a File in C#.
  • 0
  • 0
  • 3415

The FileStream object is used to write to a file. The Write method of FileStream can be used to write to a file. It takes a byte array. The following code snippet creates a FileStream object using the File.Open method that takes a file name as its first parameter and then uses the Write method of the FileStream to write it the file.

using (FileStream fs = File.Open(fileName, FileMode.Open, FileAccess.Write, FileShare.None))

    Byte[] info = new UTF8Encoding(true).GetBytes("Add more text");
    fs.Write(info, 0, info.Length);


Dinesh Beniwal

 I am working as VP Content Manager, responsible for content publishing, content development, and social relation. You can follow me on twitter @dbeniwal21

  • 4rank
  • 4M readers

Trending up