File handling READ AND WRITE TEXT FILE IN ASP.NET C#, VB
In this Post We Will Explain About is File handling READ AND WRITE TEXT FILE IN ASP.NET C#, VB With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Reading and Writing Text Files with the .NET Framework Example
In this post we will show you Best way to implement how to read or write text file using asp.net – ASP.NET,C#.NET,VB.NET , hear for Read and write the text file using vb.net with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.
HOW TO READ AND WRITE TEXT FILE IN ASP.NET C#, VB
READ AND WRITE Introduction: In this POST We are going to step by step explain the use of simple Methods like as a StreamReader and StreamWriter Class used for text file reading and writing text file Most relevant example Notepad file in Asp.Net using both C# and VB programming Language.
HTML Source
Example of the READ AND WRITE TEXT FILE IN ASP.NET C#, VB Pakainfo.com READ AND WRITE TEXT FILE IN ASP.NET C#, VB
Note: make a simple folder in Root your main folder of your simpleapplication and Name it “uploadFolder”. Text file will be here created in this dir-folder to simple write to and read from.
Asp.Net C# Code to write and read text file
//include namespace using System; //include namespace using System.IO; protected void btnliveWrite_Click(object sender, EventArgs e) { FileWrite("liveDataFile.txt"); } protected void btnliveRead_Click(object sender, EventArgs e) { livetxtredContent.Text = FileReadForm("liveDataFile.txt"); } private void FileWrite(String liveFileNm) { string getFPath = Path.Combine(Request.PhysicalApplicationPath, string.Format("{0}\\{1}", "uploadFolder", liveFileNm)); //OR string getFPath = Path.Combine(Server.MapPath("~/uploadFolder"), liveFileNm); using (StreamWriter swrite = new StreamWriter(getFPath)) { swrite.WriteLine(livetxtPutContent.Text); } } public string FileReadForm(String liveFileNm) { string fileText = string.Empty; string getFPath = Path.Combine(Request.PhysicalApplicationPath, string.Format("{0}\\{1}", "uploadFolder", liveFileNm)); //OR string getFPath = Path.Combine(Server.MapPath("~/uploadFolder"), liveFileNm); if (File.Exists(getFPath)) { using (StreamReader sr = new StreamReader(getFPath)) { fileText = sr.ReadToEnd(); } } return fileText; }
IMP Note:
In the above simple FileWrite simple function the used to StreamWriter class will make the simple text file if it this path does not exist so over write the created file if it does exist.
Asp.Net VB Code to write and read text file
Imports System.Data Imports System.IO Protected Sub btnliveRead_Click(sender As Object, e As EventArgs) livetxtredContent.Text = FileReadForm("liveDataFile.txt") End Sub Protected Sub btnliveWrite_Click(sender As Object, e As EventArgs) FileWrite("liveDataFile.txt") End Sub Public Function FileReadForm(liveFileNm As [String]) As String Dim fileText As String = String.Empty Dim getFPath As String = Path.Combine(Request.PhysicalApplicationPath, String.Format("{0}\{1}", "uploadFolder", liveFileNm)) 'OR string getFPath = Path.Combine(Server.MapPath("~/uploadFolder"), liveFileNm); If File.Exists(getFPath) Then Using sr As New StreamReader(getFPath) fileText = sr.ReadToEnd() End Using End If Return fileText End Function Private Sub FileWrite(liveFileNm As [String]) Dim getFPath As String = Path.Combine(Request.PhysicalApplicationPath, String.Format("{0}\{1}", "uploadFolder", liveFileNm)) 'OR string getFPath = Path.Combine(Server.MapPath("~/uploadFolder"), liveFileNm); Using swrite As New StreamWriter(getFPath) swrite.WriteLine(livetxtPutContent.Text) End Using End Sub
You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example
I hope you have Got What is how to read and write a text file in asp.net with c# And how it works.I would Like to have FeedBack From My Blog(Pakainfo.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(Pakainfo.com) Are Most Always Welcome.