ARTICLE

Write to a File in C#

Posted by Dinesh Beniwal Articles | C# Language August 06, 2012
In this article we will discuss about how to write to a File in C#.
Reader Level:

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);
}

 

Login to add your contents and source code to this article
comments
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts