Saturday, December 18, 2021

Read text file in asp.net C#

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.IO;

using System.Text;

using System.Threading.Tasks;

using RDotNet;

using RDotNet.NativeLibrary;

using RDotNet.Internals;

using RDotNetInstanceHelper;


public partial class Grid : Page

{


    protected void Page_Load(object sender, EventArgs e)

    {

        int length = ReadFile(@"F:\\connection string for ODK.txt");

        Response.Write(length);

        

    }


  

    static int ReadFile(string file)

    {

        int length = 0;


        

        using (StreamReader reader = new StreamReader(file))

        {

            // Reads all characters from the current position to the end of the stream asynchronously

            // and returns them as one string.

            string s = reader.ReadToEnd();


            length = s.Length;

        }

        

        return length;

    }

}

https://www.c-sharpcorner.com/UploadFile/mahesh/how-to-read-a-text-file-in-C-Sharp/

No comments:

Post a Comment