Exporting Data to txt file using C#

In this Article i am going to explain you how to Export a DataGridView(Windows) data to a Text File(.txt)first i created a Table with a name'emp'.it has 3 columns as 'id' number,'empname' varchar,'salary' number and i Inserted Some Data in 'emp' Table.Next Retrive the Data in DataGridview(windows).

AfterRetreving OutPut of Datagridview as below :

What you have data, present in datagideview that data should be export in to the txtfile.creating a text file with a coding :-Below line is creating a textfile with a name file11.just you have to give a path where your text file should be located.here I am saving my file in 'F Drive'.

Here FileMode.Create will automatically create a textfile with a name called file11.txt in 'F drive' with a FileStream Class.If your are using Io Streams class then you have to Import a NameSpace as Using Sytstem.Io;Write below code in one Button