In this article we will see how we can write our data into a file & how we can append data into a file.
System.IO.FileStream myFileStream = new System.IO.FileStream("C:\\myTemp.txt", System.IO.FileMode.CreateNew, System.IO.FileAccess.ReadWrite);
Using above line it will create a new object of the FileStream & in that we will pass the filename with path in which we want to write something or append something.
After that give a FileMode, here we will give it "CreateNew". Using this value it will create a new file but if the file is already open then it will throw an exception.
After that we will pass the File Access value as ReadWrite.
System.IO.StreamWriter myStreanWriter = new System.IO.StreamWriter(myFileStream);
The above line will create an object of the StreamWriter class and in that passing an object of the FileStream Class.
System.IO.SeekOrigin.Begin
The above line will set the pointer to the beginning of the file, because we want to write our data to the new file.
System.IO.SeekOrigin.End
Using the above line will set the pointer at the end of the file, using this you can append the data into an already exist file.
Main Code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

soundar rajPosted Mar 14, 2014, 5:15 AM
like me still learner but can understand easily and i can develop my project , tq and u r a good tutor
Dragan StamenkovicPosted Apr 16, 2013, 8:20 PM
Thank you very much for these tutorial! I appreciate your work :)
NasserPosted Aug 27, 2011, 2:24 PM
thank you alot. it was very helpfull....