Skip to content
pakainfo

Pakainfo

Web Development & Good Online education

  • Home
  • Blog
  • Categories
  • Tools
  • Full Form
  • Guest Post
  • Advertise
  • About
  • Contact Us

File handling READ AND WRITE TEXT FILE IN ASP.NET C#, VB

June 3, 2019 Pakainfo Technology, Ajax, AngularJS, ASP.NET Leave a comment

File handling READ AND WRITE TEXT FILE IN ASP.NET C#, VB

Contents

  • File handling READ AND WRITE TEXT FILE IN ASP.NET C#, VB
    • HOW TO READ AND WRITE TEXT FILE IN ASP.NET C#, VB
    • HTML Source
    • Asp.Net C# Code to write and read text file
    • Asp.Net VB Code to write and read text file
    • Related posts

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!.

Also Read This πŸ‘‰   Event Watch route change with VueJS

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


    <title>Example of the READ AND WRITE TEXT FILE IN ASP.NET C#, VB Pakainfo.com</title>


<h1>READ AND WRITE TEXT FILE IN ASP.NET C#, VB</h1>
    <form id="form1">
        <div>
            <table>
                <tr>
                    <td style="text-align:left">
                        <br />
                    </td>
                </tr>
                <tr>
                    <td style="text-align:left">
                         <br />
                    </td>
                </tr>
            </table>
        </div>
    </form>


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:

Also Read This πŸ‘‰   Angular 9/8 Material Select Box Examples

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

Also Read This πŸ‘‰   postgres drop database Using command line

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.

Related posts:

  1. How to write a variable to a file in Python?
  2. How to Read Text File in Javascript Line By Line?
  3. remove underline from link css using text-decoration Best 5 Examples
  4. Multiple image slider in html source code
  5. How To Create Image Hover Overlay Effects?
  6. PHP File file_get_contents Handling Function
  7. Implement Read More Read Less Functionality Using jQuery
  8. How to display cross domain json data using Jquery
asp net write to text filec# read and write text file line by linecreate and write text file in c#how to read a text file in c# windows forms applicationhow to read and write a text file in asp.net with c#how to read and write text file in c# windows applicationread text file in c# using streamreadervb.net write to text file

Post navigation

Previous Post:cURL POST header parameters file json request
Next Post:Laravel Dynamic Active Class Menu

Advertise With Us

Increase visibility and sales with advertising. Let us promote you online.
Click Here

Write For Us

We’re accepting well-written informative guest posts and this is a great opportunity to collaborate.
Submit a guest post to [email protected]
Contact Us

Freelance web developer

Do you want to build a modern, lightweight, responsive website quickly?
Need a Website Or Web Application Contact : [email protected]
Note: Paid Service
Contact Me

Categories

3movierulz (64) Ajax (464) AngularJS (377) ASP.NET (61) Bio (109) Bollywood (108) Codeigniter (175) CSS (98) Earn Money (69) Education (61) Entertainment (130) fullform (86) Google Adsense (63) Highcharts (77) History (40) Hollywood (109) JavaScript (1358) Jobs (42) jQuery (1423) Laravel (1088) LifeStyle (53) movierulz4 (63) Mysql (1029) Mysqli (890) php (2121) Programming (2332) Python (98) Software (167) Software (88) Stories (98) tamilrockers (104) Tamilrockers kannada (64) Tamilrockers telugu (61) Tech (143) Technology (2392) Tips and Tricks (119) Tools (207) Top10 (484) Trading (91) Trending (71) VueJs (250) Web Technology (105) webtools (192) wordpress (166) World (325)

A To Z Full Forms

Access a complete full forms list with the meaning, definition, and example of the acronym or abbreviation.
Click Here
  • Home
  • About Us
  • Terms And Conditions
  • Write For Us
  • Advertise
  • Contact Us
  • Youtube Tag Extractor
  • Info Grepper
  • Guest Posting Sites
  • Increase Domain Authority
  • Social Media Marketing
  • Freelance web developer
  • Tools
Pakainfo 9-OLD, Ganesh Sco, Kothariya Ring Road, Chokadi, Rajkot - 360002 India
E-mail : [email protected]
Pakainfo

Β© 2023 Pakainfo. All rights reserved.

Top
Subscribe On YouTube : Download Source Code
We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype Guest Posting Sites