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

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.

Also Read This πŸ‘‰   PHP Laravel 6 create Pagination Example - demo

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 πŸ‘‰   How To Create Image Hover Overlay Effects?

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.

Free Live Chat for Any Issue

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 πŸ‘‰   Check if value exists jQuery in Array – jQuery.inArray()

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.

Pakainfo
Pakainfo

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I’m a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

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
  9. Dynamically Upload Multiple Images Using PHP and 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

Search

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 (56) Ajax (464) AngularJS (377) ASP.NET (61) Bollywood (100) Codeigniter (175) CSS (98) Earn Money (61) Education (56) Entertainment (121) fullform (82) Google Adsense (62) Highcharts (77) Hollywood (101) JavaScript (1356) Jobs (40) jQuery (1422) Laravel (1087) LifeStyle (51) movierulz4 (55) Mysql (1029) Mysqli (890) Node.js (39) php (2117) Programming (2330) Python (96) ReactJS (37) Software (135) Software (83) Stories (94) tamilrockers (96) Tamilrockers kannada (56) Tamilrockers telugu (55) Tech (132) Technology (2377) Tips and Tricks (113) Tools (169) Top10 (389) Trading (69) Trending (63) VueJs (250) Web Technology (93) webtools (174) wordpress (166) World (210)

Advertise With Us

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

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
  • 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

Β© 2022 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 YouTube Tag Extractor