Export Data to Text File | C# | WinForms

Опубликовано: 13 Февраль 2026
на канале: How To 365
1,026
20

Learn How To Export Data to a Text File using C# in simple way. With this tutorial you will grasp the very basic idea of how to write in a file from databases or other sources.

Solutions -------

1. Connecting to a database to get our data into a datagridview

2. Using "System.IO.Textwriter" to write into a file of our choice

Related Or Similar Links --------

1. Sublime text editor download link (Official)

-- https://www.sublimetext.com/ --

2. Digital Clock and Date batch File (Google Drive)

-- https://bit.ly/3P9kvYP --

3. Sublime text editor download link- portable (Google Drive)

-- https://bit.ly/3spenSq -- File Password : 123

4. Sublime text editor full download link (Google Drive)

-- https://bit.ly/3vVQp3o -- File Password : 123

Note --------

Disclaimer 1

It is not recommended to download anything from unsafe or unsupervised websites

Disclaimer 2

The files provided by the owner of this YouTube channel are for countries under U.S government sanctions and are considered as gifts

Previous Videos --------

Export data to Excel | C#

--    • Export Data to Excel File | C# | WinForms   --

Youtube Call To Action -------

Don't forget to Like and Share my content and also Subscribe to my channel for more tips and tricks. This will help me grow

-- https://bit.ly/3Pakd48 --

C# Development Episode 4 Chapters -------

00:00 - How to EXPORT DATAGRIDVIEW to a TEXT file with C#
00:15 - Project creation (Windows Form App .NET FRAMEWORK)
00:47 - Application UI design
01:25 - SQL SERVER connection and data fetch and run to check
01:56 - Export to TXT File procedure
02:07 - Try - Catch clause
02:40 - How to check if a datagridview is empty using C#
03:11 - How to count datagridview column and row
04:24 - How to loop through datagridview row and column
05:17 - System.IO libraries
05:34 - Using "textwriter" to write datagridview contents into file
07:22 - How to save a file using SaveFileDialog using C#
09:22 - Remember to Close() the file after done writing in it (NOT IN THE LOOP)
09:44 - Remember to subtract 1 from row count limit in LOOP statement
10:05 - Code cleanup, beautifying output, information on export
10:25 - Final output and check
10:35 - End screen

Learn More in About Section -------

About Microsoft Visual Studio:
Visual Studio is an integrated development environment from Microsoft. It is used to develop computer programs including websites, web apps, web services and mobile apps

About C#:
C# is a general-purpose high-level programming language supporting multiple paradigms. C# encompasses static typing, strong typing, lexically scoped, imperative, declarative, functional, generic, object-oriented, and component-oriented programming disciplines.

About Microsoft SQL Server:
Microsoft SQL Server is a relational database management system developed by Microsoft. As a database server, it is a software product with the primary function of storing and retrieving data as requested by other software applications—which may run either on the same computer or on another computer across a network

About SQL:
Structured Query Language, abbreviated as SQL, is a domain-specific language used in programming and designed for managing data held in a relational database management system, or for stream processing in a relational data stream management system