Asp.net implements the method of reading data from a Txt file to a data view,
This document describes how to use asp.net to read data from a Txt file to a data view. We will share this with you for your reference. The details are as follows:
# Region reads data from the Txt file to the data view // read data from the Txt file to the data view /// </summary> /// <param name = "strExcelPath"> File path </param> /// <returns> returns a data view </returns> public static DataView GetDataFromTxt (string strTxtPath) {string strLine = ""; DataRow row; try {DataTable tbl = new DataTable (); StreamReader sr = new StreamReader (strTxtPath, Encoding. getEncoding ("GB2312"); strLine = sr. readLine (); // read the first row attribute string [] Fields = strLin E. split (new char [] {'/t'}); // read each field (separated by TAB) for (int k = 0; k <Fields. length; k ++) // Add the column attribute {tbl to the table. columns. add (Fields [k], typeof (string);} while (strLine = sr. readLine ())! = Null) {row = tbl. newRow (); string [] words = strLine. split (new char [] {'/t'}); // read each field value (separated by TAB) for (int j = 0; j <words. length; j ++) {row [j] = words [j];} tbl. rows. add (row);} sr. dispose (); sr. close (); DataView dv = new DataView (tbl); return dv ;}catch {return null ;}# endregion
I hope this article will help you design your asp.net program.
Articles you may be interested in:
- In ASP. NET, MVC transmits data from the background controller to the foreground view.
- ASP. NET operations on txt files (read, write, and save)
- Preview ASP. NET files in Word, Excel, and TXT files online
- Simple implementation code for recording visitor page access IP addresses (asp.net + txt)
- Asp.net: How to import data from a able to an Excel file and create a table
- In asp.net, use the Repeater control to drag and drop to sort and synchronize the sort of database fields
- Asp.net implements Gradview binding database data and exporting Excel
- Summary of ASP. NET database connection and data retrieval methods
- Summary of several forms of MVC data transmission in ASP. NET