File Handling in C#

 File handling is an important feature in software development, when it comes to reading or writing the data to the system or From the application.

It is something helpful in the sense when we try to write something to a file Or to read some data of any type from a particular file in order to fulfill any requirement depending upon the scenario we are facing in our application.

In this article in particular, we will learn how can we write some data to a file, then reading that data from the same file and then to display the output on the console window.

so, we will consider an example of reading and writing a text file using a c# console application, In this simple example, we will just write some text data to a notepad file, following which we will be looking to read the data from the same file and then we will display it onto the console.

So, first up lets create a c# console application, we will name it as FileHandlingExample


                                                                        
Now, we will create a program to write some data to a text file in c#.

we use the using system.IO namespace in order to perform the file handling operations in c#, so as you can see in the examples above that first we write data to a text file after which we try to read the data from the same file and display it onto the console application. 

We can consider another example of reading the data from a file line by line, 


the above example simply tries to read data from a text file line by line, we can use this approach in case if we are trying to read the data in massive chunks. 

Talha Mahmood

I have been developing Applications in Microsoft .NET technologies since 2015, and having more then 5 years of experience in .NET Technology and SQL database, also having hands in tools like C# Windows Forms, WPF, WCF, Asp.Net Web forms, Asp.Net Core, SSRS, LINQ, Entity Framework, Crystal Reports, SQL server, MySQL, MongoDB, Document DB, JQuery, JavaScript, Oracle, Web API.

Post a Comment

Previous Post Next Post